From 2484cb800a355f958eaf79a7bd7e1f54fff18c0e Mon Sep 17 00:00:00 2001 From: timothywang Date: Mon, 21 Sep 2020 19:14:53 +0800 Subject: techpack: camera: solve kernel panic Allocating memory for camera FW generates a warning if the CONFIG_DMA_API_DEBUG is turned on. The warning causes kernel panic if the flag CONFIG_PANIC_ON_WARN_DEFAULT_ENABLE is turned on. Since the warning is harmless, skip allocating memory for FW to unblock bsp debug test. Bug: 160928541 Test: device boot, GCA Change-Id: I4e6f14abc24a039eab68cb6c70e297d978d1ee5a Signed-off-by: Timothy Wang --- drivers/cam_icp/icp_hw/icp_hw_mgr/cam_icp_hw_mgr.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/cam_icp/icp_hw/icp_hw_mgr/cam_icp_hw_mgr.c b/drivers/cam_icp/icp_hw/icp_hw_mgr/cam_icp_hw_mgr.c index f76a6da..4c2e7b2 100644 --- a/drivers/cam_icp/icp_hw/icp_hw_mgr/cam_icp_hw_mgr.c +++ b/drivers/cam_icp/icp_hw/icp_hw_mgr/cam_icp_hw_mgr.c @@ -2850,8 +2850,16 @@ static int cam_icp_allocate_fw_mem(void) size_t len; dma_addr_t iova; +#ifdef CONFIG_DMA_API_DEBUG + // Allocating FW memory generates a warning when CONFIG_DMA_API_DEBUG is + // set. It causes kernel panic if CONFIG_PANIC_ON_WARN_DEFAULT_ENABLE is + // set. b/160928541 + CAM_ERR(CAM_ICP, "CONFIG_DMA_API_DEBUG is set"); + return -ENOMEM; +#else rc = cam_smmu_alloc_firmware(icp_hw_mgr.iommu_hdl, &iova, &kvaddr, &len); +#endif if (rc) return -ENOMEM; -- cgit v1.2.3 From c731eabcf4fdbd393e4b8104e4f632e8614b7452 Mon Sep 17 00:00:00 2001 From: horngchuang Date: Wed, 16 Dec 2020 22:15:08 +0800 Subject: techpack: camera: Correct the offset for Gyro calibration Bug: 175363337 Test: build pass, local verified Change-Id: If098a6649c3eb4da397e437ab16de1740803d0ea Signed-off-by: horngchuang --- .../cam_sensor_module/cam_fw_update/fw_update.c | 83 ++++++++++++++++++++++ .../cam_sensor_module/cam_fw_update/fw_update.h | 4 +- drivers/cam_sensor_module/cam_ois/cam_ois_core.c | 4 ++ drivers/cam_sensor_module/cam_ois/cam_ois_dev.h | 2 + drivers/cam_sensor_module/cam_ois/cam_ois_soc.c | 18 +++++ 5 files changed, 110 insertions(+), 1 deletion(-) diff --git a/drivers/cam_sensor_module/cam_fw_update/fw_update.c b/drivers/cam_sensor_module/cam_fw_update/fw_update.c index f68bbc7..b0ddd89 100644 --- a/drivers/cam_sensor_module/cam_fw_update/fw_update.c +++ b/drivers/cam_sensor_module/cam_fw_update/fw_update.c @@ -375,5 +375,88 @@ int getFWVersion(struct cam_sensor_ctrl_t *s_ctrl) } EXPORT_SYMBOL_GPL(getFWVersion); +int GyroOffsetCorrect(struct camera_io_master *io_master_info, uint32_t gyro_correct_index) +{ + int rc = 0; + uint32_t AddrGyroZ = 0; + uint32_t AddrAccelX = 0; + uint32_t AddrAccelY = 0; + uint32_t AddrAccelZ = 0; + uint32_t UlReadVal = 0; + + g_io_master_info = io_master_info; + if (g_io_master_info == NULL) + return -EINVAL; + + CAM_INFO(CAM_SENSOR, + "[OISFW]:%s gyro_correct_index = %d\n", + __func__, gyro_correct_index); + + if (gyro_correct_index > 0) { + // Program Memory to read + if (gyro_correct_index == 1) { + AddrGyroZ = 0x0008469C; + AddrAccelX = 0x00084698; + AddrAccelY = 0x0008469A; + AddrAccelZ = 0x0008469C; + } else if (gyro_correct_index == 2) { + AddrGyroZ = 0x00084634; + AddrAccelX = 0x00084630; + AddrAccelY = 0x00084632; + AddrAccelZ = 0x00084634; + } else { + CAM_INFO(CAM_SENSOR, + "[OISFW]:%s index is not supported : %d\n", + __func__, gyro_correct_index); + return -EINVAL; + } + } else { + CAM_INFO(CAM_SENSOR, + "[OISFW]:%s index is out of range : %d\n", + __func__, gyro_correct_index); + return -EINVAL; + } + + rc = checkHighLevelCommand(20); + if (rc != 0) { + CAM_ERR(CAM_SENSOR, + "[OISFW]:%s checkHighLevelCommand failed = %d\n", + __func__, rc); + return -EINVAL; + } else { + // Gyro Offset Z + RamWrite32A(0x3000, AddrGyroZ); + RamRead32A(0x4000, &UlReadVal); + UlReadVal = UlReadVal & 0xFFFF; + UlReadVal = ((UlReadVal << 8) & 0xff00) | ((UlReadVal >> 8) & 0x00ff); + RamWrite32A(0x03A8, UlReadVal); + + // Accel Offset X + RamWrite32A(0x3000, AddrAccelX); + RamRead32A(0x4000, &UlReadVal); + UlReadVal = (UlReadVal & 0xFFFF0000) >> 16; + UlReadVal = ((UlReadVal << 8) & 0xff00) | ((UlReadVal >> 8) & 0x00ff); + RamWrite32A(0x0454, UlReadVal); + + // Accel Offset Y + RamWrite32A(0x3000, AddrAccelY); + RamRead32A(0x4000, &UlReadVal); + UlReadVal = (UlReadVal & 0xFFFF0000) >> 16; + UlReadVal = ((UlReadVal << 8) & 0xff00) | ((UlReadVal >> 8) & 0x00ff); + RamWrite32A(0x0480, UlReadVal); + + // Accel Offset Z + RamWrite32A(0x3000, AddrAccelZ); + RamRead32A(0x4000, &UlReadVal); + UlReadVal = (UlReadVal & 0xFFFF0000) >> 16; + UlReadVal = ((UlReadVal << 8) & 0xff00) | ((UlReadVal >> 8) & 0x00ff); + RamWrite32A(0x04AC, UlReadVal); + } + + return rc; +} +EXPORT_SYMBOL_GPL(GyroOffsetCorrect); + + MODULE_LICENSE("GPL v2"); MODULE_DESCRIPTION("Fw Update"); diff --git a/drivers/cam_sensor_module/cam_fw_update/fw_update.h b/drivers/cam_sensor_module/cam_fw_update/fw_update.h index c8a1248..0872ef4 100644 --- a/drivers/cam_sensor_module/cam_fw_update/fw_update.h +++ b/drivers/cam_sensor_module/cam_fw_update/fw_update.h @@ -16,4 +16,6 @@ int GyroReCalibrate(struct camera_io_master *io_master_info, stReCalib *cal_result); int WrGyroOffsetData(struct camera_io_master *io_master_info, stReCalib *cal_result); -int getFWVersion(struct cam_sensor_ctrl_t *s_ctrl); \ No newline at end of file +int getFWVersion(struct cam_sensor_ctrl_t *s_ctrl); +int GyroOffsetCorrect(struct camera_io_master *io_master_info, + uint32_t gyro_correct_index); diff --git a/drivers/cam_sensor_module/cam_ois/cam_ois_core.c b/drivers/cam_sensor_module/cam_ois/cam_ois_core.c index d286ea9..c7d141f 100644 --- a/drivers/cam_sensor_module/cam_ois/cam_ois_core.c +++ b/drivers/cam_sensor_module/cam_ois/cam_ois_core.c @@ -952,6 +952,10 @@ static int cam_ois_pkt_parse(struct cam_ois_ctrl_t *o_ctrl, void *arg) } } + // To correct the gyro offset data + if (o_ctrl->gyro_correct_enable) + GyroOffsetCorrect(&o_ctrl->io_master_info, o_ctrl->gyro_correct_index); + rc = cam_ois_apply_settings(o_ctrl, &o_ctrl->i2c_init_data); if ((rc == -EAGAIN) && (o_ctrl->io_master_info.master_type == CCI_MASTER)) { diff --git a/drivers/cam_sensor_module/cam_ois/cam_ois_dev.h b/drivers/cam_sensor_module/cam_ois/cam_ois_dev.h index e46ee03..858d991 100644 --- a/drivers/cam_sensor_module/cam_ois/cam_ois_dev.h +++ b/drivers/cam_sensor_module/cam_ois/cam_ois_dev.h @@ -173,6 +173,8 @@ struct cam_ois_ctrl_t { struct mutex ois_shift_mutex; struct kthread_worker worker; struct task_struct *worker_thread; + uint32_t gyro_correct_enable; + uint32_t gyro_correct_index; }; #endif /*_CAM_OIS_DEV_H_ */ diff --git a/drivers/cam_sensor_module/cam_ois/cam_ois_soc.c b/drivers/cam_sensor_module/cam_ois/cam_ois_soc.c index 9c14d87..8d6f074 100644 --- a/drivers/cam_sensor_module/cam_ois/cam_ois_soc.c +++ b/drivers/cam_sensor_module/cam_ois/cam_ois_soc.c @@ -41,6 +41,24 @@ static int cam_ois_get_dt_data(struct cam_ois_ctrl_t *o_ctrl) return rc; } + if (of_property_read_u32(of_node, "gyro-correct-enable", + &o_ctrl->gyro_correct_enable) < 0) { + /* Set default gyro-correct-enable */ + CAM_INFO(CAM_OIS, + "failed to parse gyro-correct-enable, set to default"); + o_ctrl->gyro_correct_enable = 0; + } + CAM_INFO(CAM_OIS, "gyro-correct-enable %d", o_ctrl->gyro_correct_enable); + + if (of_property_read_u32(of_node, "gyro-correct-index", + &o_ctrl->gyro_correct_index) < 0) { + /* Set default gyro-correct-index */ + CAM_INFO(CAM_OIS, + "failed to parse gyro-correct-index, set to default"); + o_ctrl->gyro_correct_index = 0; + } + CAM_INFO(CAM_OIS, "gyro-correct-index %d", o_ctrl->gyro_correct_index); + if (!soc_info->gpio_data) { CAM_INFO(CAM_OIS, "No GPIO found"); return 0; -- cgit v1.2.3