int DRV_GET_CHIPID(unsigned char* buf,int length) { unsigned int i = 0; int ret = 0; if(NULL == buf) { efuse_print_error("die id buf is error.\n"); return EFUSE_ERROR; } if(length < EFUSE_CHIPID_LEN) { efuse_print_error("die id lenth is error.\n"); return EFUSE_ERROR; } memset(buf, 0, EFUSE_CHIPID_LEN); pr_info("efuse read start group %d length %d.\n", EFUSE_GRP_CHIPID, EFUSE_CHIPID_SIZE); if(0 != (ret = bsp_efuse_read((u32*)buf, EFUSE_GRP_CHIPID, EFUSE_CHIPID_SIZE))) { efuse_print_error("chip id read efuse error.\n"); return READ_EFUSE_ERROR; } for(i = 0; i < EFUSE_CHIPID_SIZE; i++) { pr_info("efuse end buf[%d] is 0x%x.\n", i, buf[i]); } pr_info("efuse read end ret %d\n", ret); return EFUSE_OK; }
/***************************************************************************** * 函 数 名 : bsp_efuse_read * * 功能描述 : 按组读取EFUSE中的数据 * * 输入参数 : group 起始group * num 读取长度(word数,不超过512/4=128) * 输出参数 : pBuf EFUSE中的数据 * * 返 回 值 : * * 其它说明 : * *****************************************************************************/ int bsp_efuse_read(u32* pBuf, const u32 group, const u32 num) { int length = 0; u32 *buf = efuse_buf; u32 chan_id = ICC_CHN_IFC << 16 | IFC_RECV_FUNC_EFUSE; EFUSE_DATA_STRU msg; if((0 == num) || (group + num > EFUSE_MAX_SIZE) || (NULL == pBuf) || (num > EFUSE_MAX_ALLOW_SIZE)) { efuse_print_error(" parameter error, group=%d, num=%d, pBuf=0x%x.\n", group, num, pBuf); return EFUSE_ERROR; } msg.start = group; msg.len = num; msg.opt = (u32)EFUSE_READ; osl_sem_down(&efuse_queue_sem_id); length = bsp_icc_send(ICC_CPU_APP, chan_id, (unsigned char*)&msg, sizeof(EFUSE_DATA_STRU)); if((unsigned int)length != sizeof(EFUSE_DATA_STRU)) { osl_sem_up(&efuse_queue_sem_id); efuse_print_error("send len(%x) != expected len(%x).\n", length, sizeof(EFUSE_DATA_STRU)); return EFUSE_ERROR; } /* coverity[lock] */ osl_sem_down(&efuse_sem_id); if(0 != efuse_ret) { osl_sem_up(&efuse_queue_sem_id); efuse_print_error("efuse icc write is fail, err= %d.\n", efuse_ret); /* coverity[missing_unlock] */ return EFUSE_ERROR; } else { memcpy(pBuf, buf, EFUSE_GROUP_SIZE * num); } osl_sem_up(&efuse_queue_sem_id); /* coverity[missing_unlock] */ return EFUSE_OK; }
int efuse_init(void) { int ret; u32 chan_id = ICC_CHN_IFC << 16 | IFC_RECV_FUNC_EFUSE; if(1 == is_efuse_init) { return EFUSE_OK; } osl_sem_init(0, &efuse_sem_id); osl_sem_init(1, &efuse_queue_sem_id); ret = bsp_icc_event_register(chan_id, (read_cb_func)bsp_efuse_data_receive, NULL, NULL, NULL);/* [false alarm]:屏蔽Fortify错误 */ if(ICC_OK != ret) { efuse_print_error("register is error.\n"); return EFUSE_ERROR; } is_efuse_init = 1;/* [false alarm]:屏蔽Fortify错误 */ efuse_print_info("efuse init ok.\n"); return EFUSE_OK; }
void DRV_DIEID_TEST(void) { int i = 0; char *buf = kzalloc(EFUSE_DIEID_LEN, GFP_KERNEL); if(NULL == buf) { efuse_print_info("alloc mem is fail.\n"); return; } if(EFUSE_OK == DRV_GET_DIEID(buf, EFUSE_DIEID_LEN)) { for(i = 0; i < EFUSE_DIEID_LEN; i++) { efuse_print_info("0x%x \n", *(buf+i)); } } else { efuse_print_error("DRV_GET_DIEID is fail.\n"); } kfree(buf); }
void efuse_handle_work(struct work_struct *work) { u32 i = 0; int length = 0; u32 channel_id = ICC_CHN_IFC << 16 | IFC_RECV_FUNC_EFUSE; EFUSE_DATA_STRU *msg = &efuse_msg; if(EFUSE_READ == (u32)msg->opt) { if(1 == efuse_debug_flag) { pr_info("efuse read start group %d length %d.\n", msg->start, msg->len); } msg->ret = bsp_efuse_read(msg->buf, msg->start,msg->len); if(1 == efuse_debug_flag) { pr_info("efuse read end group %d length %d.\n", msg->start, msg->len); for(i = 0;i < msg->len;i++) { pr_info("efuse buf[%d] is 0x%x.\n", i, msg->buf[i]); } pr_info("efuse read ret %d\n", msg->ret); } } else if(EFUSE_WRITE == (u32)msg->opt) { if(1 == efuse_debug_flag) { pr_info("efuse write start group %d length %d.\n", msg->start, msg->len); for(i = 0;i < msg->len;i++) { pr_info("efuse buf[%d] is 0x%x.\n", i, msg->buf[i]); } } msg->ret = bsp_efuse_write(msg->buf, msg->start,msg->len); if(1 == efuse_debug_flag) { pr_info("efuse write ret %d.\n", msg->ret); } } else { msg->ret = EFUSE_ERROR; } length = bsp_icc_send(ICC_CPU_MODEM, channel_id, (unsigned char*)msg, sizeof(EFUSE_DATA_STRU)); if(length != (int)sizeof(EFUSE_DATA_STRU)) { efuse_print_error("send len(%x) != expected len(%lu).\n", length, (unsigned long)sizeof(EFUSE_DATA_STRU)); return; } }
void bsp_efuse_data_receive(void) { int length = 0; u32 channel_id = ICC_CHN_IFC << 16 | IFC_RECV_FUNC_EFUSE; length = bsp_icc_read(channel_id, (u8*)&efuse_msg, sizeof(EFUSE_DATA_STRU)); if(length != (int)sizeof(EFUSE_DATA_STRU)) { efuse_print_error("read len(%x) != expected len(%lu).\n", length, (unsigned long)sizeof(EFUSE_DATA_STRU)); return; } schedule_work(&efuse_work); }
static int __init hi_efuse_comm_init(void) { int ret = 0; u32 chan_id = ICC_CHN_IFC << 16 | IFC_RECV_FUNC_EFUSE; INIT_WORK(&efuse_work, efuse_handle_work); ret = bsp_icc_event_register(chan_id, (read_cb_func)bsp_efuse_data_receive, NULL, NULL, NULL); if(0 != ret) { efuse_print_error("efuse icc register is error.\n"); return EFUSE_ERROR; } efuse_print_info("efuse comm init ok.\n"); return EFUSE_OK; }
void bsp_efuse_show(void) { unsigned int i = 0; unsigned int value = 0; for(i = 0;i < EFUSE_MAX_SIZE;i++) { if(OK == bsp_efuse_read(&value, i, 1)) { efuse_print_info("efuse group%d value = 0x%x.\n ", i, value); } else { efuse_print_error("efuse group%d read fail.\n", i); return; } } }
static int bsp_efuse_data_receive(unsigned int channel_id , unsigned int len, void* context) { int length = 0; u32 *buf = efuse_buf; EFUSE_DATA_STRU msg ; length = bsp_icc_read(channel_id, (u8*)&msg, sizeof(EFUSE_DATA_STRU)); if(length != (int)sizeof(EFUSE_DATA_STRU)) { efuse_print_error("read len(%x) != expected len(%x).\n", length, sizeof(EFUSE_DATA_STRU)); efuse_ret = -1; osl_sem_up(&efuse_sem_id); return EFUSE_ERROR; } memcpy(buf, msg.buf, EFUSE_MAX_ALLOW_SIZE*EFUSE_GROUP_SIZE); efuse_ret = msg.ret; osl_sem_up(&efuse_sem_id); return EFUSE_OK; }