From ca3c46daddb9e4330d7c6ed8fcc022713867173e Mon Sep 17 00:00:00 2001 From: handong Date: Wed, 19 Jan 2022 16:54:15 +0800 Subject: [PATCH] rhodec flash supplier distinguish[2/4] details: distinguish flash supplier Change-Id: I8c4692e80dc64cecb34f8d747ca40b44dea3b707 Reviewed-on: https://gerrit.mot.com/2174388 SME-Granted: SME Approvals Granted SLTApproved: Slta Waiver Tested-by: Jira Key Reviewed-by: Reviewed-by: XiaoFeng Wang Reviewed-by: Long Cheng Reviewed-by: Reviewed-by: Zhichao Chen Submit-Approved: Jira Key --- .../cam_sensor/cam_sensor_core.c | 74 ++++++++++++++++--- .../cam_sensor/cam_sensor_dev.h | 3 + .../cam_sensor/cam_sensor_soc.c | 7 ++ include/uapi/camera/media/cam_sensor.h | 2 + 4 files changed, 76 insertions(+), 10 deletions(-) diff --git a/drivers/cam_sensor_module/cam_sensor/cam_sensor_core.c b/drivers/cam_sensor_module/cam_sensor/cam_sensor_core.c index 83578c81c00b..107365dbf6c3 100644 --- a/drivers/cam_sensor_module/cam_sensor/cam_sensor_core.c +++ b/drivers/cam_sensor_module/cam_sensor/cam_sensor_core.c @@ -445,12 +445,14 @@ int32_t cam_sensor_update_slave_info(struct cam_cmd_probe *probe_info, s_ctrl->sensor_probe_addr_type = probe_info->addr_type; s_ctrl->sensor_probe_data_type = probe_info->data_type; - s_ctrl->probe_sub_device = probe_info->probe_sub_device; - s_ctrl->sub_device_addr = probe_info->sub_device_addr; - s_ctrl->sub_device_data_type = probe_info->sub_device_data_type; - s_ctrl->sub_device_addr_type = probe_info->sub_device_addr_type; - s_ctrl->sub_device_id_addr = probe_info->sub_device_id_addr; - s_ctrl->expected_sub_device_id = probe_info->expected_sub_device_id; + s_ctrl->probe_sub_device = probe_info->probe_sub_device; + s_ctrl->sub_device_addr = probe_info->sub_device_addr; + s_ctrl->sub_device_data_type = probe_info->sub_device_data_type; + s_ctrl->sub_device_addr_type = probe_info->sub_device_addr_type; + s_ctrl->sub_device_id_addr = probe_info->sub_device_id_addr; + s_ctrl->expected_sub_device_id = probe_info->expected_sub_device_id; + s_ctrl->sub_device_cci_master = probe_info->sub_device_cci_master; + s_ctrl->sub_device_i2c_freq_mode = probe_info->sub_device_i2c_freq_mode; CAM_DBG(CAM_SENSOR, "Sensor Addr: 0x%x sensor_id: 0x%x sensor_mask: 0x%x sensor_pipeline_delay:0x%x", @@ -714,8 +716,11 @@ int cam_sensor_match_id(struct cam_sensor_ctrl_t *s_ctrl) int cam_sensor_match_sub_device_id(struct cam_sensor_ctrl_t *s_ctrl) { int rc = 0; + int ret = 0; uint32_t sub_device_id = 0; uint16_t sensor_address = 0; + uint16_t sensor_freq_mode = 0; + uint8_t sensor_cci_master = 0; /* if hal doesn't config ProbeSubDevice parameter in sensor xml, return success immediately */ if (!s_ctrl->probe_sub_device) { @@ -730,6 +735,32 @@ int cam_sensor_match_sub_device_id(struct cam_sensor_ctrl_t *s_ctrl) s_ctrl->io_master_info.cci_client->sid = s_ctrl->sub_device_addr >> 1; } + /*if need change cci master*/ + if (s_ctrl->need_change_cci_master) { + sensor_cci_master = s_ctrl->io_master_info.cci_client->cci_i2c_master; + sensor_freq_mode = s_ctrl->io_master_info.cci_client->i2c_freq_mode; + + ret = camera_io_release(&(s_ctrl->io_master_info)); + if (ret != 0) { + CAM_ERR(CAM_SENSOR, "release sensor cci failed!"); + } + + s_ctrl->io_master_info.cci_client->cci_i2c_master = s_ctrl->sub_device_cci_master; + s_ctrl->io_master_info.cci_client->i2c_freq_mode = s_ctrl->sub_device_i2c_freq_mode; + + rc = camera_io_init(&(s_ctrl->io_master_info)); + if(rc != 0) { + ret = camera_io_release(&(s_ctrl->io_master_info)); + CAM_ERR(CAM_SENSOR, "init sensor cci failed! rc=%d, release ret=%d, try again!", rc, ret); + usleep_range(100000, 100000); + rc = camera_io_init(&(s_ctrl->io_master_info)); + if (rc != 0) { + ret = camera_io_release(&(s_ctrl->io_master_info)); + CAM_ERR(CAM_SENSOR, "try again init sensor cci failed again! rc=%d, release ret=%d", rc, ret); + } + } + } + rc = camera_io_dev_read( &(s_ctrl->io_master_info), s_ctrl->sub_device_id_addr, @@ -740,6 +771,32 @@ int cam_sensor_match_sub_device_id(struct cam_sensor_ctrl_t *s_ctrl) CAM_INFO(CAM_SENSOR, "Read sub device id: 0x%x expected sub device id 0x%x:", sub_device_id, s_ctrl->expected_sub_device_id); + /* restore sensor i2c address */ + s_ctrl->io_master_info.cci_client->sid = sensor_address; + + /* reset cci master */ + if (s_ctrl->need_change_cci_master) { + ret = camera_io_release(&(s_ctrl->io_master_info)); + if (ret != 0) { + CAM_ERR(CAM_SENSOR, "release flash cci failed! "); + } + + s_ctrl->io_master_info.cci_client->cci_i2c_master = sensor_cci_master; + s_ctrl->io_master_info.cci_client->i2c_freq_mode = sensor_freq_mode; + + rc = camera_io_init(&(s_ctrl->io_master_info)); + if(rc != 0) { + ret = camera_io_release(&(s_ctrl->io_master_info)); + CAM_ERR(CAM_SENSOR, "init sensor cci failed! rc=%d, release ret=%d, try again!", rc, ret); + usleep_range(100000, 100000); + rc = camera_io_init(&(s_ctrl->io_master_info)); + if (rc != 0) { + ret = camera_io_release(&(s_ctrl->io_master_info)); + CAM_ERR(CAM_SENSOR, "try again init sensor cci failed again! rc=%d, release ret=%d", rc, ret); + } + } + } + if (sub_device_id == s_ctrl->expected_sub_device_id) { CAM_INFO(CAM_SENSOR, "Probe sub device success,slot:%d,sub_device_addr:0x%x,sub_device_id:0x%x", @@ -753,9 +810,6 @@ int cam_sensor_match_sub_device_id(struct cam_sensor_ctrl_t *s_ctrl) rc = -EINVAL; } - /* restore sensor i2c address */ - s_ctrl->io_master_info.cci_client->sid = sensor_address; - return rc; } @@ -845,7 +899,7 @@ int32_t cam_sensor_driver_cmd(struct cam_sensor_ctrl_t *s_ctrl, rc = cam_sensor_match_sub_device_id(s_ctrl); if (rc < 0) { cam_sensor_power_down(s_ctrl); - msleep(20); + usleep_range(20000,20000); goto free_power_settings; } diff --git a/drivers/cam_sensor_module/cam_sensor/cam_sensor_dev.h b/drivers/cam_sensor_module/cam_sensor/cam_sensor_dev.h index c132b0a3846d..1883d1d48755 100644 --- a/drivers/cam_sensor_module/cam_sensor/cam_sensor_dev.h +++ b/drivers/cam_sensor_module/cam_sensor/cam_sensor_dev.h @@ -117,6 +117,9 @@ struct cam_sensor_ctrl_t { uint8_t sub_device_addr_type; uint16_t sub_device_id_addr; uint16_t expected_sub_device_id; + uint8_t sub_device_cci_master; + uint8_t sub_device_i2c_freq_mode; + bool need_change_cci_master; }; /** diff --git a/drivers/cam_sensor_module/cam_sensor/cam_sensor_soc.c b/drivers/cam_sensor_module/cam_sensor/cam_sensor_soc.c index d5cfe48223a5..dc41dacae0ea 100644 --- a/drivers/cam_sensor_module/cam_sensor/cam_sensor_soc.c +++ b/drivers/cam_sensor_module/cam_sensor/cam_sensor_soc.c @@ -187,6 +187,13 @@ static int32_t cam_sensor_driver_get_dt_data(struct cam_sensor_ctrl_t *s_ctrl) CAM_DBG(CAM_SENSOR, "cci-index %d", s_ctrl->cci_num); } + if (of_property_read_bool(of_node, "need-change-cci-master")) { + CAM_DBG(CAM_SENSOR, "need-change-cci-master found in this imgsensor"); + s_ctrl->need_change_cci_master = true; + } else { + s_ctrl->need_change_cci_master = false; + } + if (of_property_read_u32(of_node, "sensor-position-pitch", &sensordata->pos_pitch) < 0) { CAM_DBG(CAM_SENSOR, "Invalid sensor position"); diff --git a/include/uapi/camera/media/cam_sensor.h b/include/uapi/camera/media/cam_sensor.h index 49cb7da7cdfd..9dc2aee64a21 100644 --- a/include/uapi/camera/media/cam_sensor.h +++ b/include/uapi/camera/media/cam_sensor.h @@ -178,6 +178,8 @@ struct cam_cmd_probe { __u8 sub_device_addr_type; __u32 sub_device_id_addr; __u32 expected_sub_device_id; + __u8 sub_device_cci_master; + __u8 sub_device_i2c_freq_mode; } __attribute__((packed)); /**