瀏覽代碼

Merge "msm: camera: flash: Add support for qup i2c flash" into camera-kernel.lnx.5.0

Savita Patted 3 年之前
父節點
當前提交
258defb7e2

+ 57 - 6
drivers/cam_sensor_module/cam_flash/cam_flash_dev.c

@@ -428,6 +428,7 @@ static int cam_flash_component_bind(struct device *dev,
 		return -ENOMEM;
 
 	fctrl->pdev = pdev;
+	fctrl->of_node = pdev->dev.of_node;
 	fctrl->soc_info.pdev = pdev;
 	fctrl->soc_info.dev = &pdev->dev;
 	fctrl->soc_info.dev_name = pdev->name;
@@ -585,13 +586,18 @@ static int32_t cam_flash_i2c_driver_probe(struct i2c_client *client,
 {
 	int32_t rc = 0, i = 0;
 	struct cam_flash_ctrl *fctrl;
+	struct cam_hw_soc_info *soc_info = NULL;
 
-	if (client == NULL || id == NULL) {
-		CAM_ERR(CAM_FLASH, "Invalid Args client: %pK id: %pK",
-			client, id);
+	if (client == NULL) {
+		CAM_ERR(CAM_FLASH, "Invalid Args client: %pK",
+			client);
 		return -EINVAL;
 	}
 
+	if (id == NULL) {
+		CAM_DBG(CAM_FLASH, "device id is Null");
+	}
+
 	if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
 		CAM_ERR(CAM_FLASH, "%s :: i2c_check_functionality failed",
 			 client->name);
@@ -603,9 +609,9 @@ static int32_t cam_flash_i2c_driver_probe(struct i2c_client *client,
 	if (!fctrl)
 		return -ENOMEM;
 
-	i2c_set_clientdata(client, fctrl);
-
+	client->dev.driver_data = fctrl;
 	fctrl->io_master_info.client = client;
+	fctrl->of_node = client->dev.of_node;
 	fctrl->soc_info.dev = &client->dev;
 	fctrl->soc_info.dev_name = client->name;
 	fctrl->io_master_info.master_type = I2C_MASTER;
@@ -616,6 +622,49 @@ static int32_t cam_flash_i2c_driver_probe(struct i2c_client *client,
 		goto free_ctrl;
 	}
 
+	rc = cam_flash_init_default_params(fctrl);
+	if (rc) {
+		CAM_ERR(CAM_FLASH,
+				"failed: cam_flash_init_default_params rc %d",
+				rc);
+		goto free_ctrl;
+	}
+
+	soc_info = &fctrl->soc_info;
+
+	/* Initalize regulators to default parameters */
+	for (i = 0; i < soc_info->num_rgltr; i++) {
+		soc_info->rgltr[i] = devm_regulator_get(soc_info->dev,
+			soc_info->rgltr_name[i]);
+		if (IS_ERR_OR_NULL(soc_info->rgltr[i])) {
+			rc = PTR_ERR(soc_info->rgltr[i]);
+			rc  = rc ? rc : -EINVAL;
+			CAM_ERR(CAM_FLASH, "get failed for regulator %s %d",
+				soc_info->rgltr_name[i], rc);
+			goto free_ctrl;
+		}
+		CAM_DBG(CAM_FLASH, "get for regulator %s",
+			soc_info->rgltr_name[i]);
+	}
+
+	if (!soc_info->gpio_data) {
+		CAM_DBG(CAM_FLASH, "No GPIO found");
+	} else {
+		if (!soc_info->gpio_data->cam_gpio_common_tbl_size) {
+			CAM_DBG(CAM_FLASH, "No GPIO found");
+			rc = -EINVAL;
+			goto free_ctrl;
+		}
+
+		rc = cam_sensor_util_init_gpio_pin_tbl(soc_info,
+			&fctrl->power_info.gpio_num_info);
+		if ((rc < 0) || (!fctrl->power_info.gpio_num_info)) {
+			CAM_ERR(CAM_FLASH, "No/Error Flash GPIOs");
+			rc = -EINVAL;
+			goto free_ctrl;
+		}
+	}
+
 	rc = cam_flash_init_subdev(fctrl);
 	if (rc)
 		goto free_ctrl;
@@ -683,6 +732,7 @@ static struct i2c_driver cam_flash_i2c_driver = {
 	.remove = cam_flash_i2c_driver_remove,
 	.driver = {
 		.name = FLASH_DRIVER_I2C,
+		.of_match_table = cam_flash_dt_match,
 	},
 };
 
@@ -697,8 +747,9 @@ int32_t cam_flash_init_module(void)
 	}
 
 	rc = i2c_add_driver(&cam_flash_i2c_driver);
-	if (rc)
+	if (rc < 0)
 		CAM_ERR(CAM_FLASH, "i2c_add_driver failed rc: %d", rc);
+
 	return rc;
 }
 

+ 9 - 2
drivers/cam_sensor_module/cam_flash/cam_flash_soc.c

@@ -1,6 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0-only
 /*
- * Copyright (c) 2017-2020, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2017-2021, The Linux Foundation. All rights reserved.
  */
 
 #include <linux/of.h>
@@ -285,7 +285,14 @@ int cam_flash_get_dt_data(struct cam_flash_ctrl *fctrl,
 		rc = -ENOMEM;
 		goto release_soc_res;
 	}
-	of_node = fctrl->pdev->dev.of_node;
+
+	if (fctrl->of_node == NULL) {
+		CAM_ERR(CAM_FLASH, "device node is NULL");
+		rc = -EINVAL;
+		goto free_soc_private;
+	}
+
+	of_node = fctrl->of_node;
 
 	rc = cam_soc_util_get_dt_properties(soc_info);
 	if (rc) {

+ 15 - 5
drivers/cam_sensor_module/cam_sensor_io/cam_sensor_qup_i2c.c

@@ -1,6 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0-only
 /*
- * Copyright (c) 2017-2020, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2017-2021, The Linux Foundation. All rights reserved.
  */
 
 #include "cam_sensor_cmn_header.h"
@@ -31,9 +31,14 @@ static int32_t cam_qup_i2c_rxdata(
 		},
 	};
 	rc = i2c_transfer(dev_client->adapter, msgs, 2);
-	if (rc < 0)
+	if (rc < 0) {
 		CAM_ERR(CAM_SENSOR, "failed 0x%x", saddr);
-	return rc;
+		return rc;
+	}
+	/* Returns negative errno */
+	/* else the number of messages executed. */
+	/* So positive values are not errors. */
+	return 0;
 }
 
 
@@ -52,9 +57,14 @@ static int32_t cam_qup_i2c_txdata(
 		 },
 	};
 	rc = i2c_transfer(dev_client->client->adapter, msg, 1);
-	if (rc < 0)
+	if (rc < 0) {
 		CAM_ERR(CAM_SENSOR, "failed 0x%x", saddr);
-	return rc;
+		return rc;
+	}
+	/* Returns negative errno, */
+	/* else the number of messages executed. */
+	/* So positive values are not errors. */
+	return 0;
 }
 
 int32_t cam_qup_i2c_read(struct i2c_client *client,