/*
* Driver for Digigram miXart soundcards
*
- * hwdep device manager
+ * DSP firmware management
*
* Copyright (c) 2003 by Digigram <alsa@digigram.com>
*
#include <sound/driver.h>
#include <linux/interrupt.h>
+#include <linux/pci.h>
+#include <linux/firmware.h>
#include <asm/io.h>
#include <sound/core.h>
#include "mixart.h"
#include "mixart_hwdep.h"
-/* miXart hwdep interface id string */
-#define SND_MIXART_HWDEP_ID "miXart Loader"
-
-static int mixart_hwdep_open(snd_hwdep_t *hw, struct file *file)
-{
- return 0;
-}
-
-static int mixart_hwdep_release(snd_hwdep_t *hw, struct file *file)
-{
- return 0;
-}
-
/**
* wait for a value on a peudo register, exit with a timeout
*
* @param value value
* @param timeout timeout in centisenconds
*/
-static int mixart_wait_nice_for_register_value(mixart_mgr_t *mgr, u32 offset, int is_egal, u32 value, unsigned long timeout)
+static int mixart_wait_nice_for_register_value(struct mixart_mgr *mgr,
+ u32 offset, int is_egal,
+ u32 value, unsigned long timeout)
{
unsigned long end_time = jiffies + (timeout * HZ / 100);
u32 read;
/*
structures needed to upload elf code packets
*/
-typedef struct snd_mixart_elf32_ehdr snd_mixart_elf32_ehdr_t;
-
struct snd_mixart_elf32_ehdr {
u8 e_ident[16];
u16 e_type;
u16 e_shstrndx;
};
-typedef struct snd_mixart_elf32_phdr snd_mixart_elf32_phdr_t;
-
struct snd_mixart_elf32_phdr {
u32 p_type;
u32 p_offset;
u32 p_align;
};
-static int mixart_load_elf(mixart_mgr_t *mgr, snd_hwdep_dsp_image_t *dsp )
+static int mixart_load_elf(struct mixart_mgr *mgr, const struct firmware *dsp )
{
char elf32_magic_number[4] = {0x7f,'E','L','F'};
- snd_mixart_elf32_ehdr_t elf_header;
+ struct snd_mixart_elf32_ehdr *elf_header;
int i;
- if ( copy_from_user(&elf_header, dsp->image , sizeof(snd_mixart_elf32_ehdr_t)) )
- return -EFAULT;
-
+ elf_header = (struct snd_mixart_elf32_ehdr *)dsp->data;
for( i=0; i<4; i++ )
- if ( elf32_magic_number[i] != elf_header.e_ident[i] )
+ if ( elf32_magic_number[i] != elf_header->e_ident[i] )
return -EINVAL;
- if( elf_header.e_phoff != 0 ) {
- snd_mixart_elf32_phdr_t elf_programheader;
+ if( elf_header->e_phoff != 0 ) {
+ struct snd_mixart_elf32_phdr elf_programheader;
- for( i=0; i < be16_to_cpu(elf_header.e_phnum); i++ ) {
- u32 pos = be32_to_cpu(elf_header.e_phoff) + (u32)(i * be16_to_cpu(elf_header.e_phentsize));
+ for( i=0; i < be16_to_cpu(elf_header->e_phnum); i++ ) {
+ u32 pos = be32_to_cpu(elf_header->e_phoff) + (u32)(i * be16_to_cpu(elf_header->e_phentsize));
- if( copy_from_user( &elf_programheader, dsp->image + pos, sizeof(elf_programheader) ) )
- return -EFAULT;
+ memcpy( &elf_programheader, dsp->data + pos, sizeof(elf_programheader) );
if(elf_programheader.p_type != 0) {
if( elf_programheader.p_filesz != 0 ) {
- if(copy_from_user_toio( MIXART_MEM( mgr, be32_to_cpu(elf_programheader.p_vaddr)),
- dsp->image + be32_to_cpu( elf_programheader.p_offset ),
- be32_to_cpu( elf_programheader.p_filesz )))
- return -EFAULT;
+ memcpy_toio( MIXART_MEM( mgr, be32_to_cpu(elf_programheader.p_vaddr)),
+ dsp->data + be32_to_cpu( elf_programheader.p_offset ),
+ be32_to_cpu( elf_programheader.p_filesz ));
}
}
}
return 0;
}
-static int mixart_hwdep_dsp_status(snd_hwdep_t *hw, snd_hwdep_dsp_status_t *info)
-{
- mixart_mgr_t *mgr = hw->private_data;
-
- strcpy(info->id, "miXart");
- info->num_dsps = MIXART_HARDW_FILES_MAX_INDEX;
-
- if (mgr->hwdep->dsp_loaded & (1 << MIXART_MOTHERBOARD_ELF_INDEX))
- info->chip_ready = 1;
-
- info->version = MIXART_DRIVER_VERSION;
- return 0;
-}
-
/*
* get basic information and init miXart
*/
#define MIXART_FIRST_ANA_AUDIO_ID 0
#define MIXART_FIRST_DIG_AUDIO_ID 8
-static int mixart_enum_connectors(mixart_mgr_t *mgr)
+static int mixart_enum_connectors(struct mixart_mgr *mgr)
{
u32 k;
int err;
- mixart_msg_t request;
- mixart_enum_connector_resp_t connector;
- mixart_audio_info_req_t audio_info_req;
- mixart_audio_info_resp_t audio_info;
+ struct mixart_msg request;
+ struct mixart_enum_connector_resp *connector;
+ struct mixart_audio_info_req *audio_info_req;
+ struct mixart_audio_info_resp *audio_info;
+
+ connector = kmalloc(sizeof(*connector), GFP_KERNEL);
+ audio_info_req = kmalloc(sizeof(*audio_info_req), GFP_KERNEL);
+ audio_info = kmalloc(sizeof(*audio_info), GFP_KERNEL);
+ if (! connector || ! audio_info_req || ! audio_info) {
+ err = -ENOMEM;
+ goto __error;
+ }
- audio_info_req.line_max_level = MIXART_FLOAT_P_22_0_TO_HEX;
- audio_info_req.micro_max_level = MIXART_FLOAT_M_20_0_TO_HEX;
- audio_info_req.cd_max_level = MIXART_FLOAT____0_0_TO_HEX;
+ audio_info_req->line_max_level = MIXART_FLOAT_P_22_0_TO_HEX;
+ audio_info_req->micro_max_level = MIXART_FLOAT_M_20_0_TO_HEX;
+ audio_info_req->cd_max_level = MIXART_FLOAT____0_0_TO_HEX;
request.message_id = MSG_SYSTEM_ENUM_PLAY_CONNECTOR;
- request.uid = (mixart_uid_t){0,0}; /* board num = 0 */
+ request.uid = (struct mixart_uid){0,0}; /* board num = 0 */
request.data = NULL;
request.size = 0;
- err = snd_mixart_send_msg(mgr, &request, sizeof(connector), &connector);
- if((err < 0) || (connector.error_code) || (connector.uid_count > MIXART_MAX_PHYS_CONNECTORS)) {
+ err = snd_mixart_send_msg(mgr, &request, sizeof(*connector), connector);
+ if((err < 0) || (connector->error_code) || (connector->uid_count > MIXART_MAX_PHYS_CONNECTORS)) {
snd_printk(KERN_ERR "error MSG_SYSTEM_ENUM_PLAY_CONNECTOR\n");
- return -EINVAL;
+ err = -EINVAL;
+ goto __error;
}
- for(k=0; k < connector.uid_count; k++) {
- mixart_pipe_t* pipe;
+ for(k=0; k < connector->uid_count; k++) {
+ struct mixart_pipe *pipe;
if(k < MIXART_FIRST_DIG_AUDIO_ID) {
pipe = &mgr->chip[k/2]->pipe_out_ana;
pipe = &mgr->chip[(k-MIXART_FIRST_DIG_AUDIO_ID)/2]->pipe_out_dig;
}
if(k & 1) {
- pipe->uid_right_connector = connector.uid[k]; /* odd */
+ pipe->uid_right_connector = connector->uid[k]; /* odd */
} else {
- pipe->uid_left_connector = connector.uid[k]; /* even */
+ pipe->uid_left_connector = connector->uid[k]; /* even */
}
- /* snd_printk(KERN_DEBUG "playback connector[%d].object_id = %x\n", k, connector.uid[k].object_id); */
+ /* snd_printk(KERN_DEBUG "playback connector[%d].object_id = %x\n", k, connector->uid[k].object_id); */
/* TODO: really need send_msg MSG_CONNECTOR_GET_AUDIO_INFO for each connector ? perhaps for analog level caps ? */
request.message_id = MSG_CONNECTOR_GET_AUDIO_INFO;
- request.uid = connector.uid[k];
- request.data = &audio_info_req;
- request.size = sizeof(audio_info_req);
+ request.uid = connector->uid[k];
+ request.data = audio_info_req;
+ request.size = sizeof(*audio_info_req);
- err = snd_mixart_send_msg(mgr, &request, sizeof(audio_info), &audio_info);
+ err = snd_mixart_send_msg(mgr, &request, sizeof(*audio_info), audio_info);
if( err < 0 ) {
snd_printk(KERN_ERR "error MSG_CONNECTOR_GET_AUDIO_INFO\n");
- return err;
+ goto __error;
}
- /*snd_printk(KERN_DEBUG "play analog_info.analog_level_present = %x\n", audio_info.info.analog_info.analog_level_present);*/
+ /*snd_printk(KERN_DEBUG "play analog_info.analog_level_present = %x\n", audio_info->info.analog_info.analog_level_present);*/
}
request.message_id = MSG_SYSTEM_ENUM_RECORD_CONNECTOR;
- request.uid = (mixart_uid_t){0,0}; /* board num = 0 */
+ request.uid = (struct mixart_uid){0,0}; /* board num = 0 */
request.data = NULL;
request.size = 0;
- err = snd_mixart_send_msg(mgr, &request, sizeof(connector), &connector);
- if((err < 0) || (connector.error_code) || (connector.uid_count > MIXART_MAX_PHYS_CONNECTORS)) {
+ err = snd_mixart_send_msg(mgr, &request, sizeof(*connector), connector);
+ if((err < 0) || (connector->error_code) || (connector->uid_count > MIXART_MAX_PHYS_CONNECTORS)) {
snd_printk(KERN_ERR "error MSG_SYSTEM_ENUM_RECORD_CONNECTOR\n");
- return -EINVAL;
+ err = -EINVAL;
+ goto __error;
}
- for(k=0; k < connector.uid_count; k++) {
- mixart_pipe_t* pipe;
+ for(k=0; k < connector->uid_count; k++) {
+ struct mixart_pipe *pipe;
if(k < MIXART_FIRST_DIG_AUDIO_ID) {
pipe = &mgr->chip[k/2]->pipe_in_ana;
pipe = &mgr->chip[(k-MIXART_FIRST_DIG_AUDIO_ID)/2]->pipe_in_dig;
}
if(k & 1) {
- pipe->uid_right_connector = connector.uid[k]; /* odd */
+ pipe->uid_right_connector = connector->uid[k]; /* odd */
} else {
- pipe->uid_left_connector = connector.uid[k]; /* even */
+ pipe->uid_left_connector = connector->uid[k]; /* even */
}
- /* snd_printk(KERN_DEBUG "capture connector[%d].object_id = %x\n", k, connector.uid[k].object_id); */
+ /* snd_printk(KERN_DEBUG "capture connector[%d].object_id = %x\n", k, connector->uid[k].object_id); */
/* TODO: really need send_msg MSG_CONNECTOR_GET_AUDIO_INFO for each connector ? perhaps for analog level caps ? */
request.message_id = MSG_CONNECTOR_GET_AUDIO_INFO;
- request.uid = connector.uid[k];
- request.data = &audio_info_req;
- request.size = sizeof(audio_info_req);
+ request.uid = connector->uid[k];
+ request.data = audio_info_req;
+ request.size = sizeof(*audio_info_req);
- err = snd_mixart_send_msg(mgr, &request, sizeof(audio_info), &audio_info);
+ err = snd_mixart_send_msg(mgr, &request, sizeof(*audio_info), audio_info);
if( err < 0 ) {
snd_printk(KERN_ERR "error MSG_CONNECTOR_GET_AUDIO_INFO\n");
- return err;
+ goto __error;
}
- /*snd_printk(KERN_DEBUG "rec analog_info.analog_level_present = %x\n", audio_info.info.analog_info.analog_level_present);*/
+ /*snd_printk(KERN_DEBUG "rec analog_info.analog_level_present = %x\n", audio_info->info.analog_info.analog_level_present);*/
}
+ err = 0;
- return 0;
+ __error:
+ kfree(connector);
+ kfree(audio_info_req);
+ kfree(audio_info);
+
+ return err;
}
-static int mixart_enum_physio(mixart_mgr_t *mgr)
+static int mixart_enum_physio(struct mixart_mgr *mgr)
{
u32 k;
int err;
- mixart_msg_t request;
- mixart_uid_t get_console_mgr;
- mixart_return_uid_t console_mgr;
- mixart_uid_enumeration_t phys_io;
+ struct mixart_msg request;
+ struct mixart_uid get_console_mgr;
+ struct mixart_return_uid console_mgr;
+ struct mixart_uid_enumeration phys_io;
/* get the uid for the console manager */
get_console_mgr.object_id = 0;
mgr->uid_console_manager = console_mgr.uid;
request.message_id = MSG_SYSTEM_ENUM_PHYSICAL_IO;
- request.uid = (mixart_uid_t){0,0};
+ request.uid = (struct mixart_uid){0,0};
request.data = &console_mgr.uid;
request.size = sizeof(console_mgr.uid);
}
-static int mixart_first_init(mixart_mgr_t *mgr)
+static int mixart_first_init(struct mixart_mgr *mgr)
{
u32 k;
int err;
- mixart_msg_t request;
+ struct mixart_msg request;
if((err = mixart_enum_connectors(mgr)) < 0) return err;
/* send a synchro command to card (necessary to do this before first MSG_STREAM_START_STREAM_GRP_PACKET) */
/* though why not here */
request.message_id = MSG_SYSTEM_SEND_SYNCHRO_CMD;
- request.uid = (mixart_uid_t){0,0};
+ request.uid = (struct mixart_uid){0,0};
request.data = NULL;
request.size = 0;
/* this command has no data. response is a 32 bit status */
/* firmware base addresses (when hard coded) */
#define MIXART_MOTHERBOARD_XLX_BASE_ADDRESS 0x00600000
-static int mixart_hwdep_dsp_load(snd_hwdep_t *hw, snd_hwdep_dsp_image_t *dsp)
+static int mixart_dsp_load(struct mixart_mgr* mgr, int index, const struct firmware *dsp)
{
- mixart_mgr_t* mgr = hw->private_data;
int err, card_index;
u32 status_xilinx, status_elf, status_daught;
u32 val;
return -EAGAIN; /* try again later */
}
- switch (dsp->index) {
+ switch (index) {
case MIXART_MOTHERBOARD_XLX_INDEX:
/* xilinx already loaded ? */
}
/* check xilinx validity */
- snd_assert(((u32*)(dsp->image))[0]==0xFFFFFFFF, return -EINVAL);
- snd_assert(dsp->length % 4 == 0, return -EINVAL);
+ snd_assert(((u32*)(dsp->data))[0]==0xFFFFFFFF, return -EINVAL);
+ snd_assert(dsp->size % 4 == 0, return -EINVAL);
/* set xilinx status to copying */
writel_be( 1, MIXART_MEM( mgr, MIXART_PSEUDOREG_MXLX_STATUS_OFFSET ));
/* setup xilinx base address */
writel_be( MIXART_MOTHERBOARD_XLX_BASE_ADDRESS, MIXART_MEM( mgr,MIXART_PSEUDOREG_MXLX_BASE_ADDR_OFFSET ));
/* setup code size for xilinx file */
- writel_be( dsp->length, MIXART_MEM( mgr, MIXART_PSEUDOREG_MXLX_SIZE_OFFSET ));
+ writel_be( dsp->size, MIXART_MEM( mgr, MIXART_PSEUDOREG_MXLX_SIZE_OFFSET ));
/* copy xilinx code */
- if (copy_from_user_toio( MIXART_MEM( mgr, MIXART_MOTHERBOARD_XLX_BASE_ADDRESS), dsp->image, dsp->length))
- return -EFAULT;
+ memcpy_toio( MIXART_MEM( mgr, MIXART_MOTHERBOARD_XLX_BASE_ADDRESS), dsp->data, dsp->size);
/* set xilinx status to copy finished */
writel_be( 2, MIXART_MEM( mgr, MIXART_PSEUDOREG_MXLX_STATUS_OFFSET ));
writel_be( 1, MIXART_MEM( mgr, MIXART_PSEUDOREG_ELF_STATUS_OFFSET ));
/* process the copying of the elf packets */
- err = mixart_load_elf( mgr, dsp);
+ err = mixart_load_elf( mgr, dsp );
if (err < 0) return err;
/* set elf status to copy finished */
}
/* check daughterboard xilinx validity */
- snd_assert(((u32*)(dsp->image))[0]==0xFFFFFFFF, return -EINVAL);
- snd_assert(dsp->length % 4 == 0, return -EINVAL);
+ snd_assert(((u32*)(dsp->data))[0]==0xFFFFFFFF, return -EINVAL);
+ snd_assert(dsp->size % 4 == 0, return -EINVAL);
/* inform mixart about the size of the file */
- writel_be( dsp->length, MIXART_MEM( mgr, MIXART_PSEUDOREG_DXLX_SIZE_OFFSET ));
+ writel_be( dsp->size, MIXART_MEM( mgr, MIXART_PSEUDOREG_DXLX_SIZE_OFFSET ));
/* set daughterboard status to 1 */
writel_be( 1, MIXART_MEM( mgr, MIXART_PSEUDOREG_DXLX_STATUS_OFFSET ));
snd_assert(val != 0, return -EINVAL);
/* copy daughterboard xilinx code */
- if (copy_from_user_toio( MIXART_MEM( mgr, val), dsp->image, dsp->length))
- return -EFAULT;
+ memcpy_toio( MIXART_MEM( mgr, val), dsp->data, dsp->size);
/* set daughterboard status to 4 */
writel_be( 4, MIXART_MEM( mgr, MIXART_PSEUDOREG_DXLX_STATUS_OFFSET ));
/* create devices and mixer in accordance with HW options*/
for (card_index = 0; card_index < mgr->num_cards; card_index++) {
- mixart_t *chip = mgr->chip[card_index];
+ struct snd_mixart *chip = mgr->chip[card_index];
if ((err = snd_mixart_create_pcm(chip)) < 0)
return err;
}
-int snd_mixart_hwdep_new(mixart_mgr_t *mgr)
+#if defined(CONFIG_FW_LOADER) || defined(CONFIG_FW_LOADER_MODULE)
+#if !defined(CONFIG_USE_MIXARTLOADER) && !defined(CONFIG_SND_MIXART) /* built-in kernel */
+#define SND_MIXART_FW_LOADER /* use the standard firmware loader */
+#endif
+#endif
+
+#ifdef SND_MIXART_FW_LOADER
+
+int snd_mixart_setup_firmware(struct mixart_mgr *mgr)
+{
+ static char *fw_files[3] = {
+ "miXart8.xlx", "miXart8.elf", "miXart8AES.xlx"
+ };
+ char path[32];
+
+ const struct firmware *fw_entry;
+ int i, err;
+
+ for (i = 0; i < 3; i++) {
+ sprintf(path, "mixart/%s", fw_files[i]);
+ if (request_firmware(&fw_entry, path, &mgr->pci->dev)) {
+ snd_printk(KERN_ERR "miXart: can't load firmware %s\n", path);
+ return -ENOENT;
+ }
+ /* fake hwdep dsp record */
+ err = mixart_dsp_load(mgr, i, fw_entry);
+ release_firmware(fw_entry);
+ if (err < 0)
+ return err;
+ mgr->dsp_loaded |= 1 << i;
+ }
+ return 0;
+}
+
+
+#else /* old style firmware loading */
+
+/* miXart hwdep interface id string */
+#define SND_MIXART_HWDEP_ID "miXart Loader"
+
+static int mixart_hwdep_open(struct snd_hwdep *hw, struct file *file)
+{
+ return 0;
+}
+
+static int mixart_hwdep_release(struct snd_hwdep *hw, struct file *file)
+{
+ return 0;
+}
+
+static int mixart_hwdep_dsp_status(struct snd_hwdep *hw,
+ struct snd_hwdep_dsp_status *info)
+{
+ struct mixart_mgr *mgr = hw->private_data;
+
+ strcpy(info->id, "miXart");
+ info->num_dsps = MIXART_HARDW_FILES_MAX_INDEX;
+
+ if (mgr->dsp_loaded & (1 << MIXART_MOTHERBOARD_ELF_INDEX))
+ info->chip_ready = 1;
+
+ info->version = MIXART_DRIVER_VERSION;
+ return 0;
+}
+
+static int mixart_hwdep_dsp_load(struct snd_hwdep *hw,
+ struct snd_hwdep_dsp_image *dsp)
+{
+ struct mixart_mgr* mgr = hw->private_data;
+ struct firmware fw;
+ int err;
+
+ fw.size = dsp->length;
+ fw.data = vmalloc(dsp->length);
+ if (! fw.data) {
+ snd_printk(KERN_ERR "miXart: cannot allocate image size %d\n",
+ (int)dsp->length);
+ return -ENOMEM;
+ }
+ if (copy_from_user(fw.data, dsp->image, dsp->length)) {
+ vfree(fw.data);
+ return -EFAULT;
+ }
+ err = mixart_dsp_load(mgr, dsp->index, &fw);
+ vfree(fw.data);
+ if (err < 0)
+ return err;
+ mgr->dsp_loaded |= 1 << dsp->index;
+ return err;
+}
+
+int snd_mixart_setup_firmware(struct mixart_mgr *mgr)
{
int err;
- snd_hwdep_t *hw;
+ struct snd_hwdep *hw;
/* only create hwdep interface for first cardX (see "index" module parameter)*/
if ((err = snd_hwdep_new(mgr->chip[0]->card, SND_MIXART_HWDEP_ID, 0, &hw)) < 0)
hw->ops.dsp_load = mixart_hwdep_dsp_load;
hw->exclusive = 1;
sprintf(hw->name, SND_MIXART_HWDEP_ID);
- mgr->hwdep = hw;
- mgr->hwdep->dsp_loaded = 0;
- return 0;
+ mgr->dsp_loaded = 0;
+
+ return snd_card_register(mgr->chip[0]->card);
}
+
+#endif /* SND_MIXART_FW_LOADER */