Sfoglia il codice sorgente

msm: camera: sensor: return error when i3c device table empty

Do not call register with owner when device id table is empty.

CRs-Fixed: 3227008
Change-Id: Ibb86154c4c4f0b0e3d81867eb1ed049eefbc1a85
Signed-off-by: ridhshah <[email protected]>
Ridhi Shah 3 anni fa
parent
commit
c1d7ceaba0

+ 16 - 58
drivers/cam_sensor_module/cam_actuator/cam_actuator_dev.c

@@ -596,66 +596,11 @@ static struct i3c_driver cam_actuator_i3c_driver = {
 	},
 };
 
-static int cam_actuator_fill_i3c_device_id(void)
-{
-	struct device_node                      *dev;
-	int                                      num_entries;
-	int                                      i = 0;
-	uint8_t                                  ent_num = 0;
-	uint32_t                                 mid;
-	uint32_t                                 pid;
-	int                                      rc;
-
-	dev = of_find_node_by_path(I3C_SENSOR_DEV_ID_DT_PATH);
-	if (!dev) {
-		CAM_WARN(CAM_ACTUATOR, "Couldnt Find the i3c-id-table dev node");
-		return 0;
-	}
-
-	num_entries = of_property_count_u32_elems(dev, "i3c-actuator-id-table");
-	if (num_entries <= 0) {
-		CAM_WARN(CAM_ACTUATOR, "Failed while reading the property. num_entries:%d",
-			num_entries);
-		return 0;
-	}
-
-	while (i < num_entries) {
-		if (ent_num >= MAX_I3C_DEVICE_ID_ENTRIES) {
-			CAM_WARN(CAM_ACTUATOR,
-				"Num_entries are more than MAX_I3C_DEVICE_ID_ENTRIES");
-			return -ENOMEM;
-		}
-
-		rc = of_property_read_u32_index(dev, "i3c-actuator-id-table", i, &mid);
-		if (rc) {
-			CAM_ERR(CAM_ACTUATOR, "Failed in reading the MID. rc: %d", rc);
-			return rc;
-		}
-		i++;
-
-		rc = of_property_read_u32_index(dev, "i3c-actuator-id-table", i, &pid);
-		if (rc) {
-			CAM_ERR(CAM_ACTUATOR, "Failed in reading the PID. rc: %d", rc);
-			return rc;
-		}
-		i++;
-
-		CAM_DBG(CAM_ACTUATOR, "PID: 0x%x, MID: 0x%x", pid, mid);
-
-		actuator_i3c_id[ent_num].manuf_id = mid;
-		actuator_i3c_id[ent_num].match_flags = I3C_MATCH_MANUF_AND_PART;
-		actuator_i3c_id[ent_num].part_id  = pid;
-		actuator_i3c_id[ent_num].data     = 0;
-
-		ent_num++;
-	}
-
-	return 0;
-}
-
 int cam_actuator_driver_init(void)
 {
 	int32_t rc = 0;
+	struct device_node                      *dev;
+	int num_entries = 0;
 
 	rc = platform_driver_register(&cam_actuator_platform_driver);
 	if (rc < 0) {
@@ -671,7 +616,20 @@ int cam_actuator_driver_init(void)
 	}
 
 	memset(actuator_i3c_id, 0, sizeof(struct i3c_device_id) * (MAX_I3C_DEVICE_ID_ENTRIES + 1));
-	rc = cam_actuator_fill_i3c_device_id();
+
+	dev = of_find_node_by_path(I3C_SENSOR_DEV_ID_DT_PATH);
+	if (!dev) {
+		CAM_WARN(CAM_ACTUATOR, "Couldnt Find the i3c-id-table dev node");
+		return 0;
+	}
+
+	rc = cam_sensor_count_elems_i3c_device_id(dev, &num_entries,
+		"i3c-actuator-id-table");
+	if (rc)
+		return 0;
+
+	rc = cam_sensor_fill_i3c_device_id(dev, num_entries,
+		"i3c-actuator-id-table", actuator_i3c_id);
 	if (rc)
 		goto i3c_register_err;
 

+ 15 - 57
drivers/cam_sensor_module/cam_eeprom/cam_eeprom_dev.c

@@ -737,65 +737,11 @@ static struct i3c_driver cam_eeprom_i3c_driver = {
 	},
 };
 
-static int cam_eeprom_fill_i3c_device_id(void)
-{
-	struct device_node                      *dev;
-	int                                      num_entries;
-	int                                      i = 0;
-	uint8_t                                  ent_num = 0;
-	uint32_t                                 mid;
-	uint32_t                                 pid;
-	int                                      rc;
-
-	dev = of_find_node_by_path(I3C_SENSOR_DEV_ID_DT_PATH);
-	if (!dev) {
-		CAM_WARN(CAM_EEPROM, "Couldnt Find the i3c-id-table dev node");
-		return 0;
-	}
-
-	num_entries = of_property_count_u32_elems(dev, "i3c-eeprom-id-table");
-	if (num_entries <= 0) {
-		CAM_WARN(CAM_EEPROM, "Failed while reading the property. num_entries:%d",
-			num_entries);
-		return 0;
-	}
-
-	while (i < num_entries) {
-		if (ent_num >= MAX_I3C_DEVICE_ID_ENTRIES) {
-			CAM_WARN(CAM_EEPROM, "Num_entries are more than MAX_I3C_DEVICE_ID_ENTRIES");
-			return -ENOMEM;
-		}
-
-		rc = of_property_read_u32_index(dev, "i3c-eeprom-id-table", i, &mid);
-		if (rc) {
-			CAM_ERR(CAM_EEPROM, "Failed in reading the MID. rc: %d", rc);
-			return rc;
-		}
-		i++;
-
-		rc = of_property_read_u32_index(dev, "i3c-eeprom-id-table", i, &pid);
-		if (rc) {
-			CAM_ERR(CAM_EEPROM, "Failed in reading the PID. rc: %d", rc);
-			return rc;
-		}
-		i++;
-
-		CAM_DBG(CAM_EEPROM, "PID: 0x%x, MID: 0x%x", pid, mid);
-
-		eeprom_i3c_id[ent_num].manuf_id = mid;
-		eeprom_i3c_id[ent_num].match_flags = I3C_MATCH_MANUF_AND_PART;
-		eeprom_i3c_id[ent_num].part_id  = pid;
-		eeprom_i3c_id[ent_num].data     = 0;
-
-		ent_num++;
-	}
-
-	return 0;
-}
-
 int cam_eeprom_driver_init(void)
 {
 	int rc = 0;
+	struct device_node                      *dev;
+	int num_entries = 0;
 
 	rc = platform_driver_register(&cam_eeprom_platform_driver);
 	if (rc < 0) {
@@ -818,7 +764,19 @@ int cam_eeprom_driver_init(void)
 
 	memset(eeprom_i3c_id, 0, sizeof(struct i3c_device_id) * (MAX_I3C_DEVICE_ID_ENTRIES + 1));
 
-	rc = cam_eeprom_fill_i3c_device_id();
+	dev = of_find_node_by_path(I3C_SENSOR_DEV_ID_DT_PATH);
+	if (!dev) {
+		CAM_WARN(CAM_EEPROM, "Couldnt Find the i3c-id-table dev node");
+		return 0;
+	}
+
+	rc = cam_sensor_count_elems_i3c_device_id(dev, &num_entries,
+		"i3c-eeprom-id-table");
+	if (rc)
+		return 0;
+
+	rc = cam_sensor_fill_i3c_device_id(dev, num_entries,
+		"i3c-eeprom-id-table", eeprom_i3c_id);
 	if (rc)
 		goto i3c_register_err;
 

+ 16 - 57
drivers/cam_sensor_module/cam_ois/cam_ois_dev.c

@@ -557,65 +557,11 @@ static struct i3c_driver cam_ois_i3c_driver = {
 	},
 };
 
-static int cam_ois_fill_i3c_device_id(void)
-{
-	struct device_node                      *dev;
-	int                                      num_entries;
-	int                                      i = 0;
-	uint8_t                                  ent_num = 0;
-	uint32_t                                 mid;
-	uint32_t                                 pid;
-	int                                      rc;
-
-	dev = of_find_node_by_path(I3C_SENSOR_DEV_ID_DT_PATH);
-	if (!dev) {
-		CAM_WARN(CAM_OIS, "Couldnt Find the i3c-id-table dev node");
-		return 0;
-	}
-
-	num_entries = of_property_count_u32_elems(dev, "i3c-ois-id-table");
-	if (num_entries <= 0) {
-		CAM_WARN(CAM_OIS, "Failed while reading the property. num_entries:%d",
-			num_entries);
-		return 0;
-	}
-
-	while (i < num_entries) {
-		if (ent_num >= MAX_I3C_DEVICE_ID_ENTRIES) {
-			CAM_WARN(CAM_OIS, "Num_entries are more than MAX_I3C_DEVICE_ID_ENTRIES");
-			return -ENOMEM;
-		}
-
-		rc = of_property_read_u32_index(dev, "i3c-ois-id-table", i, &mid);
-		if (rc) {
-			CAM_ERR(CAM_OIS, "Failed in reading the MID. rc: %d", rc);
-			return rc;
-		}
-		i++;
-
-		rc = of_property_read_u32_index(dev, "i3c-ois-id-table", i, &pid);
-		if (rc) {
-			CAM_ERR(CAM_OIS, "Failed in reading the PID. rc: %d", rc);
-			return rc;
-		}
-		i++;
-
-		CAM_DBG(CAM_OIS, "PID: 0x%x, MID: 0x%x", pid, mid);
-
-		ois_i3c_id[ent_num].manuf_id = mid;
-		ois_i3c_id[ent_num].match_flags = I3C_MATCH_MANUF_AND_PART;
-		ois_i3c_id[ent_num].part_id  = pid;
-		ois_i3c_id[ent_num].data     = 0;
-
-		ent_num++;
-	}
-
-	return 0;
-}
-
 int cam_ois_driver_init(void)
 {
 	int rc = 0;
+	struct device_node                      *dev;
+	int num_entries = 0;
 
 	rc = platform_driver_register(&cam_ois_platform_driver);
 	if (rc) {
@@ -630,7 +576,20 @@ int cam_ois_driver_init(void)
 	}
 
 	memset(ois_i3c_id, 0, sizeof(struct i3c_device_id) * (MAX_I3C_DEVICE_ID_ENTRIES + 1));
-	rc = cam_ois_fill_i3c_device_id();
+
+	dev = of_find_node_by_path(I3C_SENSOR_DEV_ID_DT_PATH);
+	if (!dev) {
+		CAM_WARN(CAM_OIS, "Couldnt Find the i3c-id-table dev node");
+		return 0;
+	}
+
+	rc = cam_sensor_count_elems_i3c_device_id(dev, &num_entries,
+		"i3c-ois-id-table");
+	if (rc)
+		return 0;
+
+	rc = cam_sensor_fill_i3c_device_id(dev, num_entries,
+		"i3c-ois-id-table", ois_i3c_id);
 	if (rc)
 		goto i3c_register_err;
 

+ 15 - 57
drivers/cam_sensor_module/cam_sensor/cam_sensor_dev.c

@@ -581,65 +581,11 @@ static struct i3c_driver cam_sensor_i3c_driver = {
 	},
 };
 
-static int cam_sensor_fill_i3c_device_id(void)
-{
-	struct device_node                      *dev;
-	int                                      num_entries;
-	int                                      i = 0;
-	uint8_t                                  ent_num = 0;
-	uint32_t                                 mid;
-	uint32_t                                 pid;
-	int                                      rc;
-
-	dev = of_find_node_by_path(I3C_SENSOR_DEV_ID_DT_PATH);
-	if (!dev) {
-		CAM_WARN(CAM_SENSOR, "Couldnt Find the i3c-id-table dev node");
-		return 0;
-	}
-
-	num_entries = of_property_count_u32_elems(dev, "i3c-sensor-id-table");
-	if (num_entries <= 0) {
-		CAM_WARN(CAM_SENSOR, "Failed while reading the property. num_entries:%d",
-			num_entries);
-		return 0;
-	}
-
-	while (i < num_entries) {
-		if (ent_num >= MAX_I3C_DEVICE_ID_ENTRIES) {
-			CAM_WARN(CAM_SENSOR, "Num_entries are more than MAX_I3C_DEVICE_ID_ENTRIES");
-			return -ENOMEM;
-		}
-
-		rc = of_property_read_u32_index(dev, "i3c-sensor-id-table", i, &mid);
-		if (rc) {
-			CAM_ERR(CAM_SENSOR, "Failed in reading the MID. rc: %d", rc);
-			return rc;
-		}
-		i++;
-
-		rc = of_property_read_u32_index(dev, "i3c-sensor-id-table", i, &pid);
-		if (rc) {
-			CAM_ERR(CAM_SENSOR, "Failed in reading the PID. rc: %d", rc);
-			return rc;
-		}
-		i++;
-
-		CAM_DBG(CAM_SENSOR, "PID: 0x%x, MID: 0x%x", pid, mid);
-
-		sensor_i3c_id[ent_num].manuf_id = mid;
-		sensor_i3c_id[ent_num].match_flags = I3C_MATCH_MANUF_AND_PART;
-		sensor_i3c_id[ent_num].part_id  = pid;
-		sensor_i3c_id[ent_num].data     = 0;
-
-		ent_num++;
-	}
-
-	return 0;
-}
-
 int cam_sensor_driver_init(void)
 {
 	int rc;
+	struct device_node                      *dev;
+	int num_entries = 0;
 
 	rc = platform_driver_register(&cam_sensor_platform_driver);
 	if (rc < 0) {
@@ -655,7 +601,19 @@ int cam_sensor_driver_init(void)
 
 	memset(sensor_i3c_id, 0, sizeof(struct i3c_device_id) * (MAX_I3C_DEVICE_ID_ENTRIES + 1));
 
-	rc = cam_sensor_fill_i3c_device_id();
+	dev = of_find_node_by_path(I3C_SENSOR_DEV_ID_DT_PATH);
+	if (!dev) {
+		CAM_WARN(CAM_SENSOR, "Couldnt Find the i3c-id-table dev node");
+		return 0;
+	}
+
+	rc = cam_sensor_count_elems_i3c_device_id(dev, &num_entries,
+		"i3c-sensor-id-table");
+	if (rc)
+		return 0;
+
+	rc = cam_sensor_fill_i3c_device_id(dev, num_entries,
+		"i3c-sensor-id-table", sensor_i3c_id);
 	if (rc)
 		goto i3c_register_err;
 

+ 1 - 1
drivers/cam_sensor_module/cam_sensor_utils/cam_sensor_cmn_header.h

@@ -26,7 +26,7 @@
 #define CAM_I3C_DEV_PROBE_TIMEOUT_MS           10
 #define CAM_I3C_DEV_PROBE_TIMEOUT_US          (CAM_I3C_DEV_PROBE_TIMEOUT_MS * 1000)
 #define I3C_SENSOR_DEV_ID_DT_PATH              "/soc/qcom,cam-i3c-id-table"
-#define MAX_I3C_DEVICE_ID_ENTRIES              MAX_CAMERAS
+#define MAX_I3C_DEVICE_ID_ENTRIES              (MAX_CAMERAS * 2)
 
 #define CAM_SENSOR_NAME    "cam-sensor"
 #define CAM_ACTUATOR_NAME  "cam-actuator"

+ 90 - 0
drivers/cam_sensor_module/cam_sensor_utils/cam_sensor_util.c

@@ -16,6 +16,96 @@
 #define VALIDATE_VOLTAGE(min, max, config_val) ((config_val) && \
 	(config_val >= min) && (config_val <= max))
 
+int cam_sensor_count_elems_i3c_device_id(struct device_node *dev,
+	int *num_entries, char *sensor_id_table_str)
+{
+	if (!num_entries) {
+		CAM_ERR(CAM_SENSOR, "Num_entries ptr is null");
+		return -EINVAL;
+	}
+
+	if (!dev) {
+		CAM_ERR(CAM_SENSOR, "dev ptr is null");
+		return -EINVAL;
+	}
+
+	if (!sensor_id_table_str) {
+		CAM_ERR(CAM_SENSOR, "sebsor_id_table_str ptr is null");
+		return -EINVAL;
+	}
+
+	*num_entries = of_property_count_u32_elems(dev, sensor_id_table_str);
+	if (*num_entries <= 0) {
+		CAM_DBG(CAM_SENSOR, "Failed while reading the property. num_entries:%d",
+			*num_entries);
+		return -ENOENT;
+	}
+
+	if (*num_entries >= MAX_I3C_DEVICE_ID_ENTRIES) {
+		CAM_ERR(CAM_SENSOR, "Num_entries are more than MAX_I3C_DEVICE_ID_ENTRIES");
+		return -ENOMEM;
+	}
+
+	return 0;
+}
+
+int cam_sensor_fill_i3c_device_id(struct device_node *dev, int num_entries,
+	char *sensor_id_table_str, struct i3c_device_id *sensor_i3c_device_id)
+{
+	int                                      i = 0;
+	uint8_t                                  ent_num = 0;
+	uint32_t                                 mid;
+	uint32_t                                 pid;
+	int                                      rc;
+
+	if (!dev) {
+		CAM_ERR(CAM_SENSOR, "dev ptr is null");
+		return -EINVAL;
+	}
+
+	if (!sensor_id_table_str) {
+		CAM_ERR(CAM_SENSOR, "sensor_id_table_str ptr is null");
+		return -EINVAL;
+	}
+
+	if (!sensor_i3c_device_id) {
+		CAM_ERR(CAM_SENSOR, "sensor_i3c_device_id ptr is null");
+		return -EINVAL;
+	}
+
+	while (i < num_entries) {
+		if (ent_num >= MAX_I3C_DEVICE_ID_ENTRIES) {
+			CAM_WARN(CAM_SENSOR, "Num_entries are more than MAX_I3C_DEVICE_ID_ENTRIES");
+			return -ENOMEM;
+		}
+
+		rc = of_property_read_u32_index(dev, sensor_id_table_str, i, &mid);
+		if (rc) {
+			CAM_ERR(CAM_SENSOR, "Failed in reading the MID. rc: %d", rc);
+			return rc;
+		}
+		i++;
+
+		rc = of_property_read_u32_index(dev, sensor_id_table_str, i, &pid);
+		if (rc) {
+			CAM_ERR(CAM_SENSOR, "Failed in reading the PID. rc: %d", rc);
+			return rc;
+		}
+		i++;
+
+		CAM_DBG(CAM_SENSOR, "PID: 0x%x, MID: 0x%x", pid, mid);
+
+		sensor_i3c_device_id[ent_num].manuf_id = mid;
+		sensor_i3c_device_id[ent_num].match_flags = I3C_MATCH_MANUF_AND_PART;
+		sensor_i3c_device_id[ent_num].part_id  = pid;
+		sensor_i3c_device_id[ent_num].data     = 0;
+
+		ent_num++;
+	}
+
+	return 0;
+}
+
 static struct i2c_settings_list*
 	cam_sensor_get_i2c_ptr(struct i2c_settings_array *i2c_reg_settings,
 		uint32_t size)

+ 6 - 0
drivers/cam_sensor_module/cam_sensor_utils/cam_sensor_util.h

@@ -34,6 +34,12 @@
 #define QTIMER_MUL_FACTOR   10000
 #define QTIMER_DIV_FACTOR   192
 
+int cam_sensor_count_elems_i3c_device_id(struct device_node *dev,
+	int *num_entries, char *sensor_id_table_str);
+
+int cam_sensor_fill_i3c_device_id(struct device_node *dev, int num_entries,
+	char *sensor_id_table_str, struct i3c_device_id *sensor_i3c_device_id);
+
 int cam_get_dt_power_setting_data(struct device_node *of_node,
 	struct cam_hw_soc_info *soc_info,
 	struct cam_sensor_power_ctrl_t *power_info);