diff options
author | Siddartha Mohanadoss <smohanad@codeaurora.org> | 2016-09-23 15:09:02 -0700 |
---|---|---|
committer | Siddartha Mohanadoss <smohanad@codeaurora.org> | 2016-09-23 16:48:53 -0700 |
commit | 389d449ffea4464563ffc25af765c265bb382580 (patch) | |
tree | 8d4aa61bcbb89c34c855638fff4a0572bf21cab6 | |
parent | e1424860a53d22be47bb6372c0cbab86f5070b00 (diff) |
thermal: tsens: Update sensor ID index
tsens_get_hw_id_mapping() API is used by thermal
client to obtain the logical ID or HW ID mapping
for the available temperature sensors (TSENS)
controller with sensor ID details. Clients
currently query the driver on a per sensor basis.
The API update allows the clients to get the sensor
ID information at once for the available number
of sensors.
Signed-off-by: Siddartha Mohanadoss <smohanad@codeaurora.org>
Change-Id: Ibae066276b099ffb78c72a890a689f83e4df56a9
-rw-r--r-- | drivers/thermal/msm-tsens.c | 89 | ||||
-rw-r--r-- | drivers/thermal/msm_thermal.c | 18 |
2 files changed, 47 insertions, 60 deletions
diff --git a/drivers/thermal/msm-tsens.c b/drivers/thermal/msm-tsens.c index 48975538dc0d..b6d76402b726 100644 --- a/drivers/thermal/msm-tsens.c +++ b/drivers/thermal/msm-tsens.c @@ -1066,68 +1066,68 @@ 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_err("%s: TSENS controller not available\n", __func__); return -EPROBE_DEFER; } - of_node = tmdev->pdev->dev.of_node; - if (of_node == NULL) { - pr_err("Invalid of_node??\n"); + 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; } - if (!of_match_node(tsens_match, of_node)) { - pr_err("Need to read SoC specific fuse map\n"); - return -ENODEV; - } + 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"); + return -EINVAL; + } - id = of_match_node(tsens_match, of_node); - if (id == NULL) { - pr_err("can not find tsens_match of_node\n"); - return -ENODEV; - } + if (!of_match_node(tsens_match, of_node)) { + pr_err("Need to read SoC specific fuse map\n"); + return -ENODEV; + } - if (!strcmp(id->compatible, "qcom,msm8996-tsens") || - (!strcmp(id->compatible, "qcom,msmcobalt-tsens")) || - (!strcmp(id->compatible, "qcom,msmhamster-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 = + id = of_match_node(tsens_match, of_node); + if (id == NULL) { + pr_err("can not find tsens_match of_node\n"); + return -ENODEV; + } + + if (!strcmp(id->compatible, "qcom,msm8996-tsens") || + (!strcmp(id->compatible, "qcom,msmcobalt-tsens")) || + (!strcmp(id->compatible, "qcom,msmhamster-tsens"))) { + /* Assign client id's that is used to get the + * controller and hw_sensor details + */ + for (i = 0; i < tmdev->tsens_num_sensor; i++) { + sensor_client_id[idx] = tmdev->sensor[i].sensor_client_id; - id_found = true; + idx++; } - i++; - } - } else { - /* Assign the corresponding hw sensor number which is done - * prior to support for multiple controllres - */ - while (i < tmdev->tsens_num_sensor && !id_found) { - if (sensor_sw_id == tmdev->sensor[i].sensor_client_id) { - *sensor_client_id = + } else { + /* Assign the corresponding hw sensor number + * prior to support for multiple controllres + */ + 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); @@ -5700,8 +5700,6 @@ static void tsens_debugfs_init(void) } } -int tsens_sensor_sw_idx = 0; - static int tsens_thermal_zone_register(struct tsens_tm_device *tmdev) { int rc = 0, i = 0; @@ -5715,7 +5713,7 @@ static int tsens_thermal_zone_register(struct tsens_tm_device *tmdev) char name[18]; 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; if (tmdev->tsens_type == TSENS_TYPE3) { @@ -5741,7 +5739,6 @@ static int tsens_thermal_zone_register(struct tsens_tm_device *tmdev) goto fail; } } - tsens_sensor_sw_idx++; } if (tmdev->tsens_type == TSENS_TYPE3) { diff --git a/drivers/thermal/msm_thermal.c b/drivers/thermal/msm_thermal.c index ff40d6fad922..17ecd61e9ee6 100644 --- a/drivers/thermal/msm_thermal.c +++ b/drivers/thermal/msm_thermal.c @@ -2460,7 +2460,6 @@ fail: static int create_sensor_id_map(struct device *dev) { - int i = 0; int ret = 0; tsens_id_map = devm_kzalloc(dev, @@ -2471,19 +2470,10 @@ 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 */ - 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); - goto fail; - } - } + ret = tsens_get_hw_id_mapping(max_tsens_num, tsens_id_map); + if (ret) { + pr_err("Failed to get tsens id's:%d\n", ret); + goto fail; } return ret; |