hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/drivers/thermal/thermal-generic-adc.c
....@@ -1,13 +1,10 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * Generic ADC thermal driver
34 *
45 * Copyright (C) 2016 NVIDIA CORPORATION. All rights reserved.
56 *
67 * Author: Laxman Dewangan <ldewangan@nvidia.com>
7
- *
8
- * This program is free software; you can redistribute it and/or modify
9
- * it under the terms of the GNU General Public License version 2 as
10
- * published by the Free Software Foundation.
118 */
129 #include <linux/iio/consumer.h>
1310 #include <linux/kernel.h>
....@@ -28,6 +25,9 @@
2825 {
2926 int temp, temp_hi, temp_lo, adc_hi, adc_lo;
3027 int i;
28
+
29
+ if (!gti->lookup_table)
30
+ return val;
3131
3232 for (i = 0; i < gti->nlookup_table; i++) {
3333 if (val >= gti->lookup_table[2 * i + 1])
....@@ -76,14 +76,18 @@
7676 struct gadc_thermal_info *gti)
7777 {
7878 struct device_node *np = dev->of_node;
79
+ enum iio_chan_type chan_type;
7980 int ntable;
8081 int ret;
8182
8283 ntable = of_property_count_elems_of_size(np, "temperature-lookup-table",
8384 sizeof(u32));
84
- if (ntable < 0) {
85
- dev_err(dev, "Lookup table is not provided\n");
86
- return ntable;
85
+ if (ntable <= 0) {
86
+ ret = iio_get_channel_type(gti->channel, &chan_type);
87
+ if (ret || chan_type != IIO_TEMP)
88
+ dev_notice(dev,
89
+ "no lookup table, assuming DAC channel returns milliCelcius\n");
90
+ return 0;
8791 }
8892
8993 if (ntable % 2) {
....@@ -124,6 +128,14 @@
124128 if (!gti)
125129 return -ENOMEM;
126130
131
+ gti->channel = devm_iio_channel_get(&pdev->dev, "sensor-channel");
132
+ if (IS_ERR(gti->channel)) {
133
+ ret = PTR_ERR(gti->channel);
134
+ if (ret != -EPROBE_DEFER)
135
+ dev_err(&pdev->dev, "IIO channel not found: %d\n", ret);
136
+ return ret;
137
+ }
138
+
127139 ret = gadc_thermal_read_linear_lookup_table(&pdev->dev, gti);
128140 if (ret < 0)
129141 return ret;
....@@ -131,19 +143,14 @@
131143 gti->dev = &pdev->dev;
132144 platform_set_drvdata(pdev, gti);
133145
134
- gti->channel = devm_iio_channel_get(&pdev->dev, "sensor-channel");
135
- if (IS_ERR(gti->channel)) {
136
- ret = PTR_ERR(gti->channel);
137
- dev_err(&pdev->dev, "IIO channel not found: %d\n", ret);
138
- return ret;
139
- }
140
-
141146 gti->tz_dev = devm_thermal_zone_of_sensor_register(&pdev->dev, 0, gti,
142147 &gadc_thermal_ops);
143148 if (IS_ERR(gti->tz_dev)) {
144149 ret = PTR_ERR(gti->tz_dev);
145
- dev_err(&pdev->dev, "Thermal zone sensor register failed: %d\n",
146
- ret);
150
+ if (ret != -EPROBE_DEFER)
151
+ dev_err(&pdev->dev,
152
+ "Thermal zone sensor register failed: %d\n",
153
+ ret);
147154 return ret;
148155 }
149156