diff --git a/drivers/cam_sensor_module/cam_eeprom/cam_eeprom_dev.c b/drivers/cam_sensor_module/cam_eeprom/cam_eeprom_dev.c index c8149e22fd..822fc9ede4 100644 --- a/drivers/cam_sensor_module/cam_eeprom/cam_eeprom_dev.c +++ b/drivers/cam_sensor_module/cam_eeprom/cam_eeprom_dev.c @@ -451,50 +451,6 @@ static int cam_eeprom_spi_driver_probe(struct spi_device *spi) return cam_eeprom_spi_setup(spi); } -static int cam_eeprom_spi_driver_remove(struct spi_device *sdev) -{ - int i; - struct v4l2_subdev *sd = spi_get_drvdata(sdev); - struct cam_eeprom_ctrl_t *e_ctrl; - struct cam_eeprom_soc_private *soc_private; - struct cam_hw_soc_info *soc_info; - - if (!sd) { - CAM_ERR(CAM_EEPROM, "Subdevice is NULL"); - return -EINVAL; - } - - e_ctrl = (struct cam_eeprom_ctrl_t *)v4l2_get_subdevdata(sd); - if (!e_ctrl) { - CAM_ERR(CAM_EEPROM, "eeprom device is NULL"); - return -EINVAL; - } - - soc_info = &e_ctrl->soc_info; - for (i = 0; i < soc_info->num_clk; i++) - devm_clk_put(soc_info->dev, soc_info->clk[i]); - - mutex_lock(&(e_ctrl->eeprom_mutex)); - cam_eeprom_shutdown(e_ctrl); - mutex_unlock(&(e_ctrl->eeprom_mutex)); - mutex_destroy(&(e_ctrl->eeprom_mutex)); - cam_unregister_subdev(&(e_ctrl->v4l2_dev_str)); - kfree(e_ctrl->io_master_info.spi_client); - e_ctrl->io_master_info.spi_client = NULL; - soc_private = - (struct cam_eeprom_soc_private *)e_ctrl->soc_info.soc_private; - if (soc_private) { - kfree(soc_private->power_info.gpio_num_info); - soc_private->power_info.gpio_num_info = NULL; - kfree(soc_private); - soc_private = NULL; - } - v4l2_set_subdevdata(&e_ctrl->v4l2_dev_str.sd, NULL); - kfree(e_ctrl); - - return 0; -} - static int cam_eeprom_component_bind(struct device *dev, struct device *master_dev, void *data) { diff --git a/drivers/cam_utils/cam_compat.c b/drivers/cam_utils/cam_compat.c index 79c605cf01..31d6328c34 100644 --- a/drivers/cam_utils/cam_compat.c +++ b/drivers/cam_utils/cam_compat.c @@ -15,6 +15,8 @@ #include "cam_debug_util.h" #include "cam_cpas_api.h" #include "camera_main.h" +#include "cam_eeprom_dev.h" +#include "cam_eeprom_core.h" #if IS_ENABLED(CONFIG_USE_RPMH_DRV_API) #define CAM_RSC_DRV_IDENTIFIER "cam_rsc" @@ -530,3 +532,83 @@ long cam_dma_buf_set_name(struct dma_buf *dmabuf, const char *name) return 0; } #endif + +#if KERNEL_VERSION(5, 18, 0) <= LINUX_VERSION_CODE +void cam_eeprom_spi_driver_remove(struct spi_device *sdev) +{ + struct v4l2_subdev *sd = spi_get_drvdata(sdev); + struct cam_eeprom_ctrl_t *e_ctrl; + struct cam_eeprom_soc_private *soc_private; + struct cam_hw_soc_info *soc_info; + + if (!sd) { + CAM_ERR(CAM_EEPROM, "Subdevice is NULL"); + return; + } + + e_ctrl = (struct cam_eeprom_ctrl_t *)v4l2_get_subdevdata(sd); + if (!e_ctrl) { + CAM_ERR(CAM_EEPROM, "eeprom device is NULL"); + return; + } + + soc_info = &e_ctrl->soc_info; + mutex_lock(&(e_ctrl->eeprom_mutex)); + cam_eeprom_shutdown(e_ctrl); + mutex_unlock(&(e_ctrl->eeprom_mutex)); + mutex_destroy(&(e_ctrl->eeprom_mutex)); + cam_unregister_subdev(&(e_ctrl->v4l2_dev_str)); + kfree(e_ctrl->io_master_info.spi_client); + e_ctrl->io_master_info.spi_client = NULL; + soc_private = + (struct cam_eeprom_soc_private *)e_ctrl->soc_info.soc_private; + if (soc_private) { + kfree(soc_private->power_info.gpio_num_info); + soc_private->power_info.gpio_num_info = NULL; + kfree(soc_private); + soc_private = NULL; + } + v4l2_set_subdevdata(&e_ctrl->v4l2_dev_str.sd, NULL); + kfree(e_ctrl); +} +#else +int cam_eeprom_spi_driver_remove(struct spi_device *sdev) +{ + struct v4l2_subdev *sd = spi_get_drvdata(sdev); + struct cam_eeprom_ctrl_t *e_ctrl; + struct cam_eeprom_soc_private *soc_private; + struct cam_hw_soc_info *soc_info; + + if (!sd) { + CAM_ERR(CAM_EEPROM, "Subdevice is NULL"); + return -EINVAL; + } + + e_ctrl = (struct cam_eeprom_ctrl_t *)v4l2_get_subdevdata(sd); + if (!e_ctrl) { + CAM_ERR(CAM_EEPROM, "eeprom device is NULL"); + return -EINVAL; + } + + soc_info = &e_ctrl->soc_info; + mutex_lock(&(e_ctrl->eeprom_mutex)); + cam_eeprom_shutdown(e_ctrl); + mutex_unlock(&(e_ctrl->eeprom_mutex)); + mutex_destroy(&(e_ctrl->eeprom_mutex)); + cam_unregister_subdev(&(e_ctrl->v4l2_dev_str)); + kfree(e_ctrl->io_master_info.spi_client); + e_ctrl->io_master_info.spi_client = NULL; + soc_private = + (struct cam_eeprom_soc_private *)e_ctrl->soc_info.soc_private; + if (soc_private) { + kfree(soc_private->power_info.gpio_num_info); + soc_private->power_info.gpio_num_info = NULL; + kfree(soc_private); + soc_private = NULL; + } + v4l2_set_subdevdata(&e_ctrl->v4l2_dev_str.sd, NULL); + kfree(e_ctrl); + + return 0; +} +#endif diff --git a/drivers/cam_utils/cam_compat.h b/drivers/cam_utils/cam_compat.h index 756c19d46c..3714af9fb9 100644 --- a/drivers/cam_utils/cam_compat.h +++ b/drivers/cam_utils/cam_compat.h @@ -15,6 +15,7 @@ #include #include #include +#include #include "cam_csiphy_dev.h" #include "cam_cpastop_hw.h" @@ -79,4 +80,10 @@ int cam_i3c_driver_remove(struct i3c_device *client); long cam_dma_buf_set_name(struct dma_buf *dmabuf, const char *name); +#if KERNEL_VERSION(5, 18, 0) <= LINUX_VERSION_CODE +void cam_eeprom_spi_driver_remove(struct spi_device *sdev); +#else +int cam_eeprom_spi_driver_remove(struct spi_device *sdev); +#endif + #endif /* _CAM_COMPAT_H_ */