From eaea2579ad2ee58a6b6363f243ab47f18a620de0 Mon Sep 17 00:00:00 2001 From: "tin_qiquan.zhou_tmp" Date: Wed, 12 Apr 2023 18:05:32 +0800 Subject: [PATCH] bangkk: Secondary supply flash driver ic compatible details: 1.dts add distinguish-flash-supplier= 2.ioctl query cap,distinguish flash. 3.if cci read FlashIdRegAddr is FlashId,this is sencondary,flash_supplier return 1. 4.if don't find distinguish-flash-supplier,flash_supplier is default Change-Id: Ie48452465892ea4728272634010fd5c966b68986 Signed-off-by: tin_qiquan.zhou_tmp Reviewed-on: https://gerrit.mot.com/2573829 SME-Granted: SME Approvals Granted SLTApproved: Slta Waiver Tested-by: Jira Key Reviewed-by: Reviewed-by: Reviewed-by: Reviewed-by: Reviewed-by: Zhichao Chen Submit-Approved: Jira Key --- .../cam_flash/cam_flash_core.c | 95 +++++++++++++++++++ .../cam_flash/cam_flash_dev.c | 39 +++++++- .../cam_flash/cam_flash_dev.h | 5 +- include/uapi/camera/media/cam_sensor.h | 1 + 4 files changed, 137 insertions(+), 3 deletions(-) diff --git a/drivers/cam_sensor_module/cam_flash/cam_flash_core.c b/drivers/cam_sensor_module/cam_flash/cam_flash_core.c index 6c1bbaba624c..17359fd2c8d3 100644 --- a/drivers/cam_sensor_module/cam_flash/cam_flash_core.c +++ b/drivers/cam_sensor_module/cam_flash/cam_flash_core.c @@ -2117,3 +2117,98 @@ int cam_flash_apply_request(struct cam_req_mgr_apply_request *apply) return rc; } + +#ifdef CONFIG_CAMERA_FLASH_IIC_COMPATIBLE +static int cam_flash_construct_power_vio_setting( + struct cam_sensor_power_ctrl_t *power_info) +{ + int rc = 0; + + power_info->power_setting_size = 2; + power_info->power_setting = + kzalloc(sizeof(struct cam_sensor_power_setting) * 2, + GFP_KERNEL); + if (!power_info->power_setting) + return -ENOMEM; + + power_info->power_setting[0].seq_type = SENSOR_VIO; + power_info->power_setting[0].seq_val = CAM_VIO; + power_info->power_setting[0].config_val = 1; + power_info->power_setting[0].delay = 2; + power_info->power_setting[1].seq_type = SENSOR_CUSTOM_GPIO1; + power_info->power_setting[1].seq_val = 0; + power_info->power_setting[1].config_val = 1; + power_info->power_setting[1].delay = 0; + + power_info->power_down_setting_size = 2; + power_info->power_down_setting = + kzalloc(sizeof(struct cam_sensor_power_setting) * 2, + GFP_KERNEL); + if (!power_info->power_down_setting) { + rc = -ENOMEM; + goto free_power_settings; + } + + power_info->power_down_setting[0].seq_type = SENSOR_CUSTOM_GPIO1; + power_info->power_down_setting[0].seq_val = 0; + power_info->power_down_setting[0].config_val = 0; + power_info->power_down_setting[0].seq_type = SENSOR_VIO; + power_info->power_down_setting[0].seq_val = CAM_VIO; + power_info->power_down_setting[0].config_val = 0; + + return rc; + +free_power_settings: + kfree(power_info->power_setting); + power_info->power_setting = NULL; + power_info->power_setting_size = 0; + return rc; +} + +int cam_flash_fill_vreg_setting(struct cam_flash_ctrl *fctrl) +{ + int rc = 0; + + rc = cam_flash_construct_power_vio_setting( + &fctrl->power_info); + if (rc) { + CAM_ERR(CAM_FLASH, "Failed Flash Power VIO Setting: rc=%d\n", rc); + return rc; + } + rc = msm_camera_fill_vreg_params(&fctrl->soc_info, + fctrl->power_info.power_setting, + fctrl->power_info.power_setting_size); + if(rc) + { + CAM_ERR(CAM_FLASH, "Failed Flash Fill Power Up Params: rc=%d\n", rc); + return rc; + } + rc = msm_camera_fill_vreg_params(&fctrl->soc_info, + fctrl->power_info.power_down_setting, + fctrl->power_info.power_down_setting_size); + if(rc) + { + CAM_ERR(CAM_FLASH, "Failed Flash Fill Power Down Params: rc=%d\n", rc); + return rc; + } + return rc; +} + +int cam_flash_fill_i2c_default_setting(struct cam_flash_ctrl *fctrl, uint32_t slave_addr) +{ + int rc = 0; + + struct cam_cmd_i2c_info i2c_info={0}; + i2c_info.slave_addr = slave_addr; + i2c_info.i2c_freq_mode = I2C_STANDARD_MODE; + + rc = cam_flash_slaveInfo_pkt_parser( + fctrl, (uint32_t *)&i2c_info, sizeof(struct cam_cmd_i2c_info)); + if (rc < 0) { + CAM_ERR(CAM_FLASH, + "Failed parsing slave info: rc: %d", + rc); + } + return rc; +} +#endif diff --git a/drivers/cam_sensor_module/cam_flash/cam_flash_dev.c b/drivers/cam_sensor_module/cam_flash/cam_flash_dev.c index 011ce8d8ecb1..6aae862ed4a5 100644 --- a/drivers/cam_sensor_module/cam_flash/cam_flash_dev.c +++ b/drivers/cam_sensor_module/cam_flash/cam_flash_dev.c @@ -141,7 +141,10 @@ static int32_t cam_flash_driver_cmd(struct cam_flash_ctrl *fctrl, } case CAM_QUERY_CAP: { struct cam_flash_query_cap_info flash_cap = {0}; - +#ifdef CONFIG_CAMERA_FLASH_IIC_COMPATIBLE + uint32_t flash_iic_supplier[3]; + uint32_t flashid=0; +#endif CAM_DBG(CAM_FLASH, "CAM_QUERY_CAP"); flash_cap.slot_info = fctrl->soc_info.index; flash_cap.flash_type = soc_private->flash_type; @@ -159,7 +162,39 @@ static int32_t cam_flash_driver_cmd(struct cam_flash_ctrl *fctrl, for (i = 0; i < fctrl->torch_num_sources; i++) flash_cap.max_current_torch[i] = soc_private->torch_max_current[i]; - +#ifdef CONFIG_CAMERA_FLASH_IIC_COMPATIBLE + rc = of_property_read_u32_array(fctrl->of_node, "distinguish-flash-supplier", + flash_iic_supplier, 3); + if (!rc) { + CAM_DBG(CAM_FLASH, "Distinguish IIC Flash Supplier dev:0x%x addr:0x%x data:0x%x", + flash_iic_supplier[0],flash_iic_supplier[1],flash_iic_supplier[2]); + if (cam_flash_fill_vreg_setting(fctrl)){ + CAM_ERR(CAM_FLASH, "Flash Fill Vreg Failed"); + goto release_mutex; + } + if (fctrl->func_tbl.power_ops(fctrl, true)){ + CAM_ERR(CAM_FLASH, "Power Up Failed"); + goto release_mutex; + } + if (cam_flash_fill_i2c_default_setting(fctrl, flash_iic_supplier[0])){ + CAM_ERR(CAM_FLASH, "Failed Flash Fill I2C Setting rc =%d",rc); + goto release_mutex; + } + rc = camera_io_dev_read(&(fctrl->io_master_info), + flash_iic_supplier[1],&flashid, + CAMERA_SENSOR_I2C_TYPE_BYTE, + CAMERA_SENSOR_I2C_TYPE_BYTE); + CAM_DBG(CAM_FLASH, "flashid=%d",flashid); + if ((!rc) && (flashid == flash_iic_supplier[2])) + flash_cap.flash_supplier = 1; + else + flash_cap.flash_supplier = 0; + if (fctrl->func_tbl.power_ops(fctrl, false)){ + CAM_ERR(CAM_FLASH, "Power Down Failed"); + goto release_mutex; + } + } +#endif if (copy_to_user(u64_to_user_ptr(cmd->handle), &flash_cap, sizeof(struct cam_flash_query_cap_info))) { CAM_ERR(CAM_FLASH, "Failed Copy to User"); diff --git a/drivers/cam_sensor_module/cam_flash/cam_flash_dev.h b/drivers/cam_sensor_module/cam_flash/cam_flash_dev.h index 8f76d5e8173e..59af237869c4 100644 --- a/drivers/cam_sensor_module/cam_flash/cam_flash_dev.h +++ b/drivers/cam_sensor_module/cam_flash/cam_flash_dev.h @@ -242,7 +242,10 @@ int cam_flash_pmic_flush_request(struct cam_flash_ctrl *fctrl, enum cam_flash_flush_type, uint64_t req_id); void cam_flash_shutdown(struct cam_flash_ctrl *fctrl); int cam_flash_release_dev(struct cam_flash_ctrl *fctrl); - +#ifdef CONFIG_CAMERA_FLASH_IIC_COMPATIBLE +int cam_flash_fill_i2c_default_setting(struct cam_flash_ctrl *fctrl, uint32_t slave_addr); +int cam_flash_fill_vreg_setting(struct cam_flash_ctrl *fctrl); +#endif /** * @brief : API to register FLASH hw to platform framework. * @return struct platform_device pointer on on success, or ERR_PTR() on error. diff --git a/include/uapi/camera/media/cam_sensor.h b/include/uapi/camera/media/cam_sensor.h index 7f52004c4f85..92d6672ba37d 100644 --- a/include/uapi/camera/media/cam_sensor.h +++ b/include/uapi/camera/media/cam_sensor.h @@ -508,6 +508,7 @@ struct cam_flash_query_cap_info { __u32 max_duration_flash[CAM_FLASH_MAX_LED_TRIGGERS]; __u32 max_current_torch[CAM_FLASH_MAX_LED_TRIGGERS]; __u32 flash_type; + __u32 flash_supplier; } __attribute__ ((packed)); #endif