mixart_hwdep.c
来自「优龙2410linux2.6.8内核源代码」· C语言 代码 · 共 573 行 · 第 1/2 页
C
573 行
/* * Driver for Digigram miXart soundcards * * hwdep device manager * * Copyright (c) 2003 by Digigram <alsa@digigram.com> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */#include <sound/driver.h>#include <linux/interrupt.h>#include <asm/io.h>#include <sound/core.h>#include "mixart.h"#include "mixart_mixer.h"#include "mixart_core.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 mgr pointer to miXart manager structure * @param offset unsigned pseudo_register base + offset of value * @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){ unsigned long end_time = jiffies + (timeout * HZ / 100); u32 read; do { /* we may take too long time in this loop. * so give controls back to kernel if needed. */ cond_resched(); read = readl_be( MIXART_MEM( mgr, offset )); if(is_egal) { if(read == value) return 0; } else { /* wait for different value */ if(read != value) return 0; } } while ( time_after_eq(end_time, jiffies) ); return -EBUSY;}/* 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_machine; u32 e_version; u32 e_entry; u32 e_phoff; u32 e_shoff; u32 e_flags; u16 e_ehsize; u16 e_phentsize; u16 e_phnum; u16 e_shentsize; u16 e_shnum; 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_vaddr; u32 p_paddr; u32 p_filesz; u32 p_memsz; u32 p_flags; u32 p_align;};static int mixart_load_elf(mixart_mgr_t *mgr, snd_hwdep_dsp_image_t *dsp ){ char elf32_magic_number[4] = {0x7f,'E','L','F'}; snd_mixart_elf32_ehdr_t elf_header; int i; if ( copy_from_user(&elf_header, dsp->image , sizeof(snd_mixart_elf32_ehdr_t)) ) return -EFAULT; for( i=0; i<4; 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; 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; 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; } } } } return 0;}static int mixart_hwdep_dsp_status(snd_hwdep_t *hw, snd_hwdep_dsp_status_t *info){ mixart_mgr_t *mgr = snd_magic_cast(mixart_mgr_t, hw->private_data, return -ENXIO); 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 *//* audio IDs for request to the board */#define MIXART_FIRST_ANA_AUDIO_ID 0#define MIXART_FIRST_DIG_AUDIO_ID 8static int mixart_enum_connectors(mixart_mgr_t *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; 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.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)) { snd_printk(KERN_ERR "error MSG_SYSTEM_ENUM_PLAY_CONNECTOR\n"); return -EINVAL; } for(k=0; k < connector.uid_count; k++) { mixart_pipe_t* pipe; if(k < MIXART_FIRST_DIG_AUDIO_ID) { pipe = &mgr->chip[k/2]->pipe_out_ana; } else { pipe = &mgr->chip[(k-MIXART_FIRST_DIG_AUDIO_ID)/2]->pipe_out_dig; } if(k & 1) { pipe->uid_right_connector = connector.uid[k]; /* odd */ } else { 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); */ /* 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); 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; } /*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.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)) { snd_printk(KERN_ERR "error MSG_SYSTEM_ENUM_RECORD_CONNECTOR\n"); return -EINVAL; } for(k=0; k < connector.uid_count; k++) { mixart_pipe_t* pipe; if(k < MIXART_FIRST_DIG_AUDIO_ID) { pipe = &mgr->chip[k/2]->pipe_in_ana; } else { pipe = &mgr->chip[(k-MIXART_FIRST_DIG_AUDIO_ID)/2]->pipe_in_dig; } if(k & 1) { pipe->uid_right_connector = connector.uid[k]; /* odd */ } else { 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); */ /* 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); 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; } /*snd_printk(KERN_DEBUG "rec analog_info.analog_level_present = %x\n", audio_info.info.analog_info.analog_level_present);*/ } return 0;}static int mixart_enum_physio(mixart_mgr_t *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; /* get the uid for the console manager */ get_console_mgr.object_id = 0; get_console_mgr.desc = MSG_CONSOLE_MANAGER | 0; /* cardindex = 0 */ request.message_id = MSG_CONSOLE_GET_CLOCK_UID; request.uid = get_console_mgr; request.data = &get_console_mgr; request.size = sizeof(get_console_mgr); err = snd_mixart_send_msg(mgr, &request, sizeof(console_mgr), &console_mgr); if( (err < 0) || (console_mgr.error_code != 0) ) {
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?