BCM_I2C函数更改

版本:sdk-xgs-robo-6.3.8
平台:BCM53344
应用:控制POE芯片

描述:POE控制芯片使用PD69200,使用i2c与其通信,每次需要发送15字节数据,并接受15字节的返回数据。

1.更改函数
打开文件sdk
-xgs-robo-6.3.8/src/soc/i2c/smbus.c 更改如下: int soc_i2c_block_read(int unit, i2c_saddr_t saddr, uint8 com, uint8* count, uint8* data) { //... 省略 ... I2C_LOCK(unit); // 53344芯片在定义了BCM_CMICM_SUPPORT,所以会运行下面的代码。 #ifdef BCM_CMICM_SUPPORT if(soc_feature(unit, soc_feature_cmicm) && !SOC_IS_SAND(unit)) { retry:
  //这个函数是smbus协议的命令格式。与I2C有些区别。注释掉发送地址和com的地方。
  //直接读取数据
// rval = SOC_I2C_TX_ADDR(saddr); // WRITE_CMIC_I2CM_SMBUS_MASTER_DATA_WRITEr(unit, rval); // rval = com; // WRITE_CMIC_I2CM_SMBUS_MASTER_DATA_WRITEr(unit, rval); rval = SOC_I2C_RX_ADDR(saddr); soc_reg_field_set(unit, CMIC_I2CM_SMBUS_MASTER_DATA_WRITEr, &rval, MASTER_WR_STATUSf, 1); /* Last Byte */ WRITE_CMIC_I2CM_SMBUS_MASTER_DATA_WRITEr(unit, rval);     //更改要接受的数据个数。默认是0,因此会读取0个数据。
    //查看芯片手册,需要将CMIC_I2CM_SMBus_Master_Command寄存器的最低8位(RD_BYTE_COUNT),设置为要读取的字节个数。
// rval = 0; rval = *count; soc_reg_field_set(unit, CMIC_I2CM_SMBUS_MASTER_COMMANDr, &rval, SMBUS_PROTOCOLf, SMBUS_BLOCK_READ); WRITE_CMIC_I2CM_SMBUS_MASTER_COMMANDr(unit,rval); rv = smbus_start_wait(unit); if (rv == SOC_E_NONE) {
    //直接读取即可,这一部分也不需要,smbus协议才需要
// READ_CMIC_I2CM_SMBUS_MASTER_DATA_READr(unit, &rval); // *count = (uint8) (rval & 0xff); ptr = data; for( i = 0; i < *count; i++, ptr++) { READ_CMIC_I2CM_SMBUS_MASTER_DATA_READr(unit, &rval); *ptr = (uint8) (rval & 0xff); } } else if (rt-- > 0) { goto retry; } else { rv = SOC_E_TIMEOUT; } } else  //后面的不运行 #endif   // ... 省略 ...
}
//同理,write函数也进行注释 int soc_i2c_block_write(int unit, i2c_saddr_t saddr, uint8 com, uint8 count, uint8* data) { int i,rv = SOC_E_NONE; uint8* ptr = NULL; #ifdef BCM_CMICM_SUPPORT uint32 rval; int rt = 5; #endif soc_cm_debug(DK_I2C, "i2c%d: soc_i2c_block_write %02x bytes @ %02x - %02x\n", unit, count, saddr, com); #ifdef BCM_CALADAN3_SVK if (unit == -1) { return cpu_i2c_block_write(unit, saddr, com, data, count); } #endif I2C_LOCK(unit); #ifdef BCM_CMICM_SUPPORT if(soc_feature(unit, soc_feature_cmicm) && !SOC_IS_SAND(unit)) { retry: rval = SOC_I2C_TX_ADDR(saddr); WRITE_CMIC_I2CM_SMBUS_MASTER_DATA_WRITEr(unit, rval); // rval = com; // WRITE_CMIC_I2CM_SMBUS_MASTER_DATA_WRITEr(unit, rval); // rval = count; // WRITE_CMIC_I2CM_SMBUS_MASTER_DATA_WRITEr(unit, rval); ptr = data; for( i = 0; i < (int) (count - 1); i++, ptr++) { rval = (uint32) *ptr; WRITE_CMIC_I2CM_SMBUS_MASTER_DATA_WRITEr(unit, rval); } rval = (uint32) *ptr; soc_reg_field_set(unit, CMIC_I2CM_SMBUS_MASTER_DATA_WRITEr, &rval, MASTER_WR_STATUSf, 1); /* Last Byte */ WRITE_CMIC_I2CM_SMBUS_MASTER_DATA_WRITEr(unit, rval); rval = 0; soc_reg_field_set(unit, CMIC_I2CM_SMBUS_MASTER_COMMANDr, &rval, SMBUS_PROTOCOLf, SMBUS_BLOCK_WRITE); WRITE_CMIC_I2CM_SMBUS_MASTER_COMMANDr(unit,rval); rv = smbus_start_wait(unit); if (rv != SOC_E_NONE && rt-- > 0) { goto retry; } else if (rt < 0) { rv = SOC_E_TIMEOUT; } } else #endif

2.导出全局符号
打开文件 sdk/systems/linux/kernel/modules/include/bcmx_export.h
最后添加:
  #include <soc/i2c.h>
  EXPORT_SYMBOL(soc_i2c_is_attached);
  EXPORT_SYMBOL(soc_i2c_attach);
  EXPORT_SYMBOL(soc_i2c_block_read);
  EXPORT_SYMBOL(soc_i2c_block_write);

之后从新编译SDK即可。

 

posted @ 2016-03-25 16:12  SuperTao1024  阅读(1443)  评论(0编辑  收藏  举报