1. 写一系列寄存器操作:
lc1120_write_regs(codec, lc1120_init_data, ARRAY_SIZE(lc1120_init_data)
2. 数据结构定义和数据内容:
typedef struct lc1120_i2c_data
{
unsigned char nreg; //寄存器地址
unsigned char nvalue; //要写入的值
unsigned char nmask; //要写入的位掩码
unsigned char ndelay_times; //写完后延时
}CODEC_I2C_DATA_T;
static CODEC_I2C_DATA_T lc1120_init_data[]=
{
{LC1120_R93, 0x01, 0xff, 0x01},
{LC1120_R5, 0x99, 0xff, 0x01},
{LC1120_R84, 0x76, 0xff, 0x00},
{LC1120_R87, 0xf7, 0xff, 0x01},
{LC1120_R86, 0x58, 0xff, 0x01},
{LC1120_R89, 0xb0, 0xff, 0x01},
{LC1120_R88, 0x48, 0xff, 0x01},
};
3. 具体实现方式:
static int lc1120_write_regs(struct snd_soc_codec *codec,
CODEC_I2C_DATA_T *pInitHandle, int nLength)
{
int i=0;
int nRst =0;
unsigned char nData=0;
for( i=0; i<nLength; i++) //用array_size 计算出循环次数
{
nData = lc1120_read(codec, pInitHandle[i].nreg); //先读出指定地址的寄存器值
if(pInitHandle[i].nmask)
{
nData &= (~pInitHandle[i].nmask); //掩码操作
}
nData = pInitHandle[i].nvalue|nData; //计算得出要写入的值
nRst =lc1120_write(codec, pInitHandle[i].nreg, nData); //写入寄存器
if (nRst)
break;
mdelay(pInitHandle[i].ndelay_times); //如过需要延时,就执行延时操作
}
return nRst;
真的很经典的代码。。