.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
---|
1 | 2 | /* |
---|
2 | 3 | * Generic ADC thermal driver |
---|
3 | 4 | * |
---|
4 | 5 | * Copyright (C) 2016 NVIDIA CORPORATION. All rights reserved. |
---|
5 | 6 | * |
---|
6 | 7 | * 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. |
---|
11 | 8 | */ |
---|
12 | 9 | #include <linux/iio/consumer.h> |
---|
13 | 10 | #include <linux/kernel.h> |
---|
.. | .. |
---|
28 | 25 | { |
---|
29 | 26 | int temp, temp_hi, temp_lo, adc_hi, adc_lo; |
---|
30 | 27 | int i; |
---|
| 28 | + |
---|
| 29 | + if (!gti->lookup_table) |
---|
| 30 | + return val; |
---|
31 | 31 | |
---|
32 | 32 | for (i = 0; i < gti->nlookup_table; i++) { |
---|
33 | 33 | if (val >= gti->lookup_table[2 * i + 1]) |
---|
.. | .. |
---|
76 | 76 | struct gadc_thermal_info *gti) |
---|
77 | 77 | { |
---|
78 | 78 | struct device_node *np = dev->of_node; |
---|
| 79 | + enum iio_chan_type chan_type; |
---|
79 | 80 | int ntable; |
---|
80 | 81 | int ret; |
---|
81 | 82 | |
---|
82 | 83 | ntable = of_property_count_elems_of_size(np, "temperature-lookup-table", |
---|
83 | 84 | 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; |
---|
87 | 91 | } |
---|
88 | 92 | |
---|
89 | 93 | if (ntable % 2) { |
---|
.. | .. |
---|
124 | 128 | if (!gti) |
---|
125 | 129 | return -ENOMEM; |
---|
126 | 130 | |
---|
| 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 | + |
---|
127 | 139 | ret = gadc_thermal_read_linear_lookup_table(&pdev->dev, gti); |
---|
128 | 140 | if (ret < 0) |
---|
129 | 141 | return ret; |
---|
.. | .. |
---|
131 | 143 | gti->dev = &pdev->dev; |
---|
132 | 144 | platform_set_drvdata(pdev, gti); |
---|
133 | 145 | |
---|
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 | | - |
---|
141 | 146 | gti->tz_dev = devm_thermal_zone_of_sensor_register(&pdev->dev, 0, gti, |
---|
142 | 147 | &gadc_thermal_ops); |
---|
143 | 148 | if (IS_ERR(gti->tz_dev)) { |
---|
144 | 149 | 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); |
---|
147 | 154 | return ret; |
---|
148 | 155 | } |
---|
149 | 156 | |
---|