⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tlv320.c

📁 嵌入式linux系统下hi3510平台的osd开发源码
💻 C
📖 第 1 页 / 共 2 页
字号:
/* 
 * extdrv/peripheral/ada/tlv320.c
 *
 * Copyright (c) 2006 Hisilicon Co., Ltd. 
 *
 * 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
 *
 * 
 * History: 
 *      10-April-2006 create this file
 */


#include <linux/kernel.h>
#include <linux/version.h>
#include <linux/module.h>
#include <linux/config.h>
#include <linux/types.h>
#include <linux/errno.h>
#include <linux/fcntl.h>
#include <linux/mm.h>
#include <linux/proc_fs.h>
#include <linux/fs.h>
#include <linux/slab.h>
#include <linux/smp_lock.h>
#include <linux/init.h>
#include <asm/uaccess.h>
#include <asm/hardware.h>
#include <asm/io.h>
#include <asm/system.h>
#include <linux/miscdevice.h>

#include "tlv320.h"
#include "hi_i2c.h"


//unsigned int IIC_device_addr[2] = {0x34, 0x36};

#ifdef HI3510DVS
	/* for dvs */
	unsigned int IIC_device_addr[2] = {0x34, 0x36};  
#elif defined HI3510VP
	/* for vp */
	unsigned int IIC_device_addr[2] = {0x36, 0x36}; 
#endif

#define     LINE_INPUT                      0 
#define     MIC_INPUT                       1
#define     LEFT                            0x00
#define     RIGHT                           0x01
#define     Lline_vol_ctrl    		    0x00       /*0000000 0*/
#define     Rline_vol_ctrl    		    0x02       /*0000001 0*/
#define     Lhp_vol_ctrl      		    0x04       /*0000010 0*/
#define     Rhp_vol_ctrl      		    0x06       /*0000011 0*/
#define     Analog_path_ctrl  		    0x09       /*0000100 1*/
#define     Digitl_path_ctrl  		    0x0a       /*0000101 0*/
#define     Power_down_ctrl   		    0x0c       /*0000110 0*/
#define     Digitl_intf_ctrl  		    0x0e       /*0000111 0*/
#define     Sample_rate_ctrl  		    0x10       /*0001000 0*/
#define     Digitl_intf_activ 		    0x12       /*0001001 0*/
#define     Reset_reg         		    0x1e       /*0001111 0*/

static unsigned int  open_cnt = 0;	
static unsigned int  u32PortIdx = 0;
/*
 *	support two extern codec but now only one codec used in board
 *     	In this module, codec configs is set according to the array
 */
static   unsigned short gu8RegValue[2][10] = 
{
	{0x17,0x17,0xf9,0xf9,0x12,0x00,0x02,0x42,0x0c,0x01},
	{0x17,0x17,0xf9,0xf9,0x12,0x00,0x02,0x42,0x0c,0x01}
};

/*
 *	device open. set counter
 */
static int tlv320_open(struct inode * inode, struct file * file)
{
    	if(0 == open_cnt++)
    		return 0;    	
    	return -1 ;
}

/*
 *	Close device, Do nothing!
 */
static int tlv320_close(struct inode *inode ,struct file *file)
{
	open_cnt--;
    	return 0;
}

/****************ioctl arguments used set code attr ,specification belown:**************
 *SET_SAMPLERATE                :set codec samplerate
 *LEFT_INPUT_VOLUME_MODIFY      :
 *                               Left headphone volume control (1111001 = 0 dB default)
 *                               1111111 = +6 dB, 79 steps between +6 dB and .73 dB (mute), 
 *                               0110000 = .73 dB (mute),any thing below 0110000 does 
 *                               nothing .  still in muted
 *RIGHT_INPUT_VOLUME_MODIFY     :
 *                               Right headphone volume control (1111001 = 0 dB default)
 *                               1111111 = +6 dB, 79 steps between +6 dB and .73 dB (mute), 
 *                               0110000 = .73 dB (mute),any thing below 0110000 does 
 *                               nothing .  still in muted
 *LINE_INPUT_MUTE               :Right/Left line input mute
 *MIC_INPUT_MUTE                :mute mic input
 *LEFT_HEADPHONE_VOLUME_MODIFY  :
 *                               Left headphone volume control (1111001 = 0 dB default)
 *                               1111111 = +6 dB, 79 steps between +6 dB and .73 dB (mute), 
 *                               0110000 = .73 dB (mute),any thing below 0110000 does 
 *                               nothing .  still in muted
 *RIGHt_HEADPHONE_VOLUME_MODIFY :
 *                               Right headphone volume control (1111001 = 0 dB default)
 *                               1111111 = +6 dB, 79 steps between +6 dB and .73 dB (mute), 
 *                               0110000 = .73 dB (mute),any thing below 0110000 does 
 *                               nothing .  still in muted
 *HEADPHONE_VOLUME_MUTE         :mute headphone 
 **************************************************************************************** */
static int tlv320_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
{
    	unsigned int __user *argp = (unsigned int __user *)arg;
    	unsigned int tmp ,samplerate ,which_ada;
    	unsigned int volume,channel,which_path,which_chn;

	switch(cmd)
        	{
	
        		case SET_TLV_SAMPLERATE :
                        	get_user(tmp,argp);
                              	samplerate = (tmp&0x0fffffff);                              	
                              	which_ada  = (tmp&0xf0000000);
                              	which_ada  = which_ada >> 28;
                              	switch(samplerate)
                              	{
                                	   case SET_8K_SAMPLERATE:
                                        	    gu8RegValue[which_ada][8] = 0x0C;
                                            	hi_i2c_write(IIC_device_addr[which_ada], \
                                            	Sample_rate_ctrl, gu8RegValue[which_ada][8]); 
                                            	printk("ADA 8K sample rate is setted.\n");
                                            	break;
                                                
                                    	case SET_32K_SAMPLERATE:
                                            	gu8RegValue[which_ada][8] = 0x18;
                                            	hi_i2c_write(IIC_device_addr[which_ada], \
                                            	Sample_rate_ctrl, gu8RegValue[which_ada][8]); 
                                            	printk("ADA 32K sample rate is setted.\n");
                                            	break;
                                                
                                    	case SET_48K_SAMPLERATE:
                                            	gu8RegValue[which_ada][8] = 0x00;
                                            	hi_i2c_write(IIC_device_addr[which_ada], \
                                            	Sample_rate_ctrl, gu8RegValue[which_ada][8]); 
                                            	printk("ADA 48K sample rate is setted.\n");
                                            	break;
                                                
                                    	default :
                                            	printk("inval sample rate\n");
                                            	break;
                              	}
                            	break;

    			case ANALOG_INPUT_PATH :
                            	  get_user(tmp,argp);
                            	  which_path = (tmp&0x0fffffff);
                            	  gu8RegValue[u32PortIdx][4] = which_path;
                            	  which_ada  = (tmp&0xf0000000);
                            	  which_ada  = which_ada >> 28;
                            	  tmp = which_path & 0x04;
                            	  if(tmp)
                            	  	hi_i2c_write(IIC_device_addr[which_ada], Power_down_ctrl,  0x01);   //MIC input
                            	  else
                            	  	hi_i2c_write(IIC_device_addr[which_ada], Power_down_ctrl,  0x02);   //Line input
                                hi_i2c_write(IIC_device_addr[which_ada], Analog_path_ctrl, \
                                gu8RegValue[u32PortIdx][4]); 
                                break;
    			case LEFT_INPUT_VOLUME_MODIFY:
                                get_user(tmp,argp);
                                volume    =(tmp & 0x0ff); 
                                which_ada =(tmp & 0xf0000000);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -