这两周一直在调AIC3104的驱动,这是个音频codec芯片,可以实现语音对讲功能。
AIC3104是通过I2C方式与CPU通信,来设置寄存器,另外是IIS接口进行语音的Mic_in和Line_out功能。
下面是aic3104的驱动源代码:
/* extdrv/peripheral/vda/adv7179.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.
*
*
* History:
* 17-Apr-2006 create this file
*
*/
#include <linux/unistd.h>
#include <linux/module.h>
//#include <linux/config.h>
#include <linux/errno.h>
#include <linux/miscdevice.h>
#include <linux/fcntl.h>
#include <linux/init.h>
#include <linux/delay.h>
#include <linux/proc_fs.h>
#include <linux/workqueue.h>
#include <asm/uaccess.h>
#include <asm/system.h>
#include <asm/io.h>
//#include <linux/kcom.h>
#include <linux/random.h>
//#include "stapp_main.h"
#include "sti7105.h"
#include "stsys.h"
#include "stddefs.h"
#include "sti2c.h"
#include "staudlx_aic3104.h"
//#include "stcommon.h"
//#include "stavmem.h"
///PRE-DEFINITIONS/
//module name string
#define MOD_STR "aic3104"
#define MOD_STR_E "aic3104 ERROR"
//chip and id register addr
#define CHIP_A_I2C_ADDR 0x30//0x30//0x18
#define I2C0 0x00
//#define TRUE (bool) 1
/***************************************************
(1). AIC3104 I2S work mode
Define 0xd0 if work as master
Define 0x00 if work as slave
***************************************************/
#define AIC3104_WORK_MODE 0x00
/***************************************************
(2). Global debug info switch
***************************************************/
#define GLOBAL_DEBUG
//AIC3104 version info.
#define AIC3104_VER_MIN 0// 0~63
#define AIC3104_VER_SEC 0// 0~63
#define AIC3104_VER_MAJ 1// 0~31
#define AIC3104_VER_DAY 25// 1~31
#define AIC3104_VER_MON 3// 1~12
#define AIC3104_VER_YER 10// 00~63
static STI2C_Handle_t i2c_handle;
static int nbpages = 0, chains[2] = {0,0};
typedef enum _tagDRV_ERR_CODE_
{
//general return code
NO_ERROR = 0,
ERR_NO_DEV ,
ERR_GPIO_I2C_RD,
ERR_GPIO_I2C_WR,
ERR_VERSION_CHK,
ERR_DRV_REG,
ERR_OUT_OF_RANGE,
ERR_INVALID_CMD
}DRV_ERR_CODE;
/*
ST_ErrorCode_t STI2C_Read ( STI2C_Handle_t Handle, //chip, I2CHandle
U8 *Buffer_p, //read reg
U32 MaxLen, //MAX_BYTE_READ,
U32 Timeout, //100,
U32 *ActLen_p) //target buffer
ST_ErrorCode_t STI2C_Write( STI2C_Handle_t Handle,// ----chip
const U8 *Buffer_p, //write reg
U32 NumberToWrite, // -- bytes
U32 Timeout, //new
U32 *ActLen_p) // source buffer
//#define cfg_bytes_writ