Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 474d2ee4 authored by Linux Build Service Account's avatar Linux Build Service Account Committed by Gerrit - the friendly Code Review server
Browse files

Merge "thermal: tsens: Update sensor ID index"

parents f5e620ea 4b3fa4b2
Loading
Loading
Loading
Loading
+40 −39
Original line number Diff line number Diff line
/* Copyright (c) 2012-2016, The Linux Foundation. All rights reserved.
/* Copyright (c) 2012-2017, The Linux Foundation. All rights reserved.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 and
@@ -979,6 +979,7 @@ static int32_t get_tsens_sensor_for_client_id(struct tsens_tm_device *tmdev,
	}

	if (!strcmp(id->compatible, "qcom,msm8996-tsens") ||
		(!strcmp(id->compatible, "qcom,msm8953-tsens")) ||
		(!strcmp(id->compatible, "qcom,msmcobalt-tsens"))) {
		while (i < tmdev->tsens_num_sensor && !id_found) {
			if (tmdev->sensor[i].sensor_client_id ==
@@ -1106,20 +1107,28 @@ static int tsens_get_sw_id_mapping_for_controller(
	return 0;
}

int tsens_get_hw_id_mapping(int sensor_sw_id, int *sensor_client_id)
int tsens_get_hw_id_mapping(int thermal_sensor_num, int *sensor_client_id)
{
	int i = 0;
	bool id_found = false;
	struct tsens_tm_device *tmdev = NULL;
	struct device_node *of_node = NULL;
	const struct of_device_id *id;
	uint32_t tsens_max_sensors = 0, idx = 0, i = 0;

	tmdev = get_tsens_controller_for_client_id(sensor_sw_id);
	if (tmdev == NULL) {
		pr_debug("TSENS early init not done\n");
	if (list_empty(&tsens_device_list)) {
		pr_debug("%s: TSENS controller not available\n", __func__);
		return -EPROBE_DEFER;
	}

	list_for_each_entry(tmdev, &tsens_device_list, list)
		tsens_max_sensors += tmdev->tsens_num_sensor;

	if (tsens_max_sensors != thermal_sensor_num) {
		pr_err("TSENS total sensors is %d, thermal expects:%d\n",
			tsens_max_sensors, thermal_sensor_num);
		return -EINVAL;
	}

	list_for_each_entry(tmdev, &tsens_device_list, list) {
		of_node = tmdev->pdev->dev.of_node;
		if (of_node == NULL) {
			pr_err("Invalid of_node??\n");
@@ -1138,35 +1147,28 @@ int tsens_get_hw_id_mapping(int sensor_sw_id, int *sensor_client_id)
		}

	if (!strcmp(id->compatible, "qcom,msm8996-tsens") ||
		(!strcmp(id->compatible, "qcom,msm8953-tsens")) ||
		(!strcmp(id->compatible, "qcom,msmcobalt-tsens"))) {
		/* Assign a client id which will be used to get the
		 * controller and hw_sensor details
		 */
		while (i < tmdev->tsens_num_sensor && !id_found) {
			if (sensor_sw_id == tmdev->sensor[i].sensor_client_id) {
				*sensor_client_id =
			for (i = 0; i < tmdev->tsens_num_sensor; i++) {
				sensor_client_id[idx] =
					tmdev->sensor[i].sensor_client_id;
				id_found = true;
			}
			i++;
				idx++;
			}
		} else {
		/* Assign the corresponding hw sensor number which is done
			/* Assign the corresponding hw sensor number
			 * prior to support for multiple controllres
			 */
		while (i < tmdev->tsens_num_sensor && !id_found) {
			if (sensor_sw_id == tmdev->sensor[i].sensor_sw_id) {
				*sensor_client_id =
			for (i = 0; i < tmdev->tsens_num_sensor; i++) {
				sensor_client_id[idx] =
					tmdev->sensor[i].sensor_hw_num;
				id_found = true;
				idx++;
			}
			i++;
		}
	}

	if (!id_found)
		return -EINVAL;

	return 0;
}
EXPORT_SYMBOL(tsens_get_hw_id_mapping);
@@ -5873,7 +5875,7 @@ static int tsens_thermal_zone_register(struct tsens_tm_device *tmdev)
					tmdev->sensor[i].sensor_hw_num);
		else
			snprintf(name, sizeof(name), "tsens_tz_sensor%d",
					tsens_sensor_sw_idx);
					tmdev->sensor[i].sensor_client_id);

		tmdev->sensor[i].mode = THERMAL_DEVICE_ENABLED;
		tmdev->sensor[i].tm = tmdev;
@@ -5900,7 +5902,6 @@ static int tsens_thermal_zone_register(struct tsens_tm_device *tmdev)
				goto fail;
			}
		}
		tsens_sensor_sw_idx++;
	}

	if (tmdev->tsens_type == TSENS_TYPE3) {
+5 −15
Original line number Diff line number Diff line
/* Copyright (c) 2012-2016, The Linux Foundation. All rights reserved.
/* Copyright (c) 2012-2017, The Linux Foundation. All rights reserved.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 and
@@ -2360,7 +2360,6 @@ fail:

static int create_sensor_id_map(struct device *dev)
{
	int i = 0;
	int ret = 0;

	tsens_id_map = devm_kzalloc(dev,
@@ -2371,20 +2370,11 @@ static int create_sensor_id_map(struct device *dev)
		return -ENOMEM;
	}

	for (i = 0; i < max_tsens_num; i++) {
		ret = tsens_get_hw_id_mapping(i, &tsens_id_map[i]);
		/* If return -ENXIO, hw_id is default in sequence */
	ret = tsens_get_hw_id_mapping(max_tsens_num, tsens_id_map);
	if (ret) {
			if (ret == -ENXIO) {
				tsens_id_map[i] = i;
				ret = 0;
			} else {
				pr_err("Failed to get hw id for id:%d.err:%d\n",
						i, ret);
		pr_err("Failed to get tsens id's:%d\n", ret);
		goto fail;
	}
		}
	}

	return ret;
fail: