forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-10-09 244b2c5ca8b14627e4a17755e5922221e121c771
kernel/drivers/hwmon/ab8500.c
....@@ -1,8 +1,8 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * Copyright (C) ST-Ericsson 2010 - 2013
34 * Author: Martin Persson <martin.persson@stericsson.com>
45 * Hongbo Zhang <hongbo.zhang@linaro.org>
5
- * License Terms: GNU General Public License v2
66 *
77 * When the AB8500 thermal warning temperature is reached (threshold cannot
88 * be changed by SW), an interrupt is set, and if no further action is taken
....@@ -17,20 +17,24 @@
1717 #include <linux/hwmon-sysfs.h>
1818 #include <linux/mfd/abx500.h>
1919 #include <linux/mfd/abx500/ab8500-bm.h>
20
-#include <linux/mfd/abx500/ab8500-gpadc.h>
2120 #include <linux/module.h>
2221 #include <linux/platform_device.h>
2322 #include <linux/power/ab8500.h>
2423 #include <linux/reboot.h>
2524 #include <linux/slab.h>
2625 #include <linux/sysfs.h>
26
+#include <linux/iio/consumer.h>
2727 #include "abx500.h"
2828
2929 #define DEFAULT_POWER_OFF_DELAY (HZ * 10)
3030 #define THERMAL_VCC 1800
3131 #define PULL_UP_RESISTOR 47000
32
-/* Number of monitored sensors should not greater than NUM_SENSORS */
33
-#define NUM_MONITORED_SENSORS 4
32
+
33
+#define AB8500_SENSOR_AUX1 0
34
+#define AB8500_SENSOR_AUX2 1
35
+#define AB8500_SENSOR_BTEMP_BALL 2
36
+#define AB8500_SENSOR_BAT_CTRL 3
37
+#define NUM_MONITORED_SENSORS 4
3438
3539 struct ab8500_gpadc_cfg {
3640 const struct abx500_res_to_temp *temp_tbl;
....@@ -40,7 +44,8 @@
4044 };
4145
4246 struct ab8500_temp {
43
- struct ab8500_gpadc *gpadc;
47
+ struct iio_channel *aux1;
48
+ struct iio_channel *aux2;
4449 struct ab8500_btemp *btemp;
4550 struct delayed_work power_off_work;
4651 struct ab8500_gpadc_cfg cfg;
....@@ -82,15 +87,21 @@
8287 int voltage, ret;
8388 struct ab8500_temp *ab8500_data = data->plat_data;
8489
85
- if (sensor == BAT_CTRL) {
86
- *temp = ab8500_btemp_get_batctrl_temp(ab8500_data->btemp);
87
- } else if (sensor == BTEMP_BALL) {
90
+ if (sensor == AB8500_SENSOR_BTEMP_BALL) {
8891 *temp = ab8500_btemp_get_temp(ab8500_data->btemp);
89
- } else {
90
- voltage = ab8500_gpadc_convert(ab8500_data->gpadc, sensor);
91
- if (voltage < 0)
92
- return voltage;
93
-
92
+ } else if (sensor == AB8500_SENSOR_BAT_CTRL) {
93
+ *temp = ab8500_btemp_get_batctrl_temp(ab8500_data->btemp);
94
+ } else if (sensor == AB8500_SENSOR_AUX1) {
95
+ ret = iio_read_channel_processed(ab8500_data->aux1, &voltage);
96
+ if (ret < 0)
97
+ return ret;
98
+ ret = ab8500_voltage_to_temp(&ab8500_data->cfg, voltage, temp);
99
+ if (ret < 0)
100
+ return ret;
101
+ } else if (sensor == AB8500_SENSOR_AUX2) {
102
+ ret = iio_read_channel_processed(ab8500_data->aux2, &voltage);
103
+ if (ret < 0)
104
+ return ret;
94105 ret = ab8500_voltage_to_temp(&ab8500_data->cfg, voltage, temp);
95106 if (ret < 0)
96107 return ret;
....@@ -164,10 +175,6 @@
164175 if (!ab8500_data)
165176 return -ENOMEM;
166177
167
- ab8500_data->gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
168
- if (IS_ERR(ab8500_data->gpadc))
169
- return PTR_ERR(ab8500_data->gpadc);
170
-
171178 ab8500_data->btemp = ab8500_btemp_get();
172179 if (IS_ERR(ab8500_data->btemp))
173180 return PTR_ERR(ab8500_data->btemp);
....@@ -181,15 +188,25 @@
181188 ab8500_data->cfg.tbl_sz = ab8500_temp_tbl_a_size;
182189
183190 data->plat_data = ab8500_data;
191
+ ab8500_data->aux1 = devm_iio_channel_get(&data->pdev->dev, "aux1");
192
+ if (IS_ERR(ab8500_data->aux1)) {
193
+ if (PTR_ERR(ab8500_data->aux1) == -ENODEV)
194
+ return -EPROBE_DEFER;
195
+ dev_err(&data->pdev->dev, "failed to get AUX1 ADC channel\n");
196
+ return PTR_ERR(ab8500_data->aux1);
197
+ }
198
+ ab8500_data->aux2 = devm_iio_channel_get(&data->pdev->dev, "aux2");
199
+ if (IS_ERR(ab8500_data->aux2)) {
200
+ if (PTR_ERR(ab8500_data->aux2) == -ENODEV)
201
+ return -EPROBE_DEFER;
202
+ dev_err(&data->pdev->dev, "failed to get AUX2 ADC channel\n");
203
+ return PTR_ERR(ab8500_data->aux2);
204
+ }
184205
185
- /*
186
- * ADC_AUX1 and ADC_AUX2, connected to external NTC
187
- * BTEMP_BALL and BAT_CTRL, fixed usage
188
- */
189
- data->gpadc_addr[0] = ADC_AUX1;
190
- data->gpadc_addr[1] = ADC_AUX2;
191
- data->gpadc_addr[2] = BTEMP_BALL;
192
- data->gpadc_addr[3] = BAT_CTRL;
206
+ data->gpadc_addr[0] = AB8500_SENSOR_AUX1;
207
+ data->gpadc_addr[1] = AB8500_SENSOR_AUX2;
208
+ data->gpadc_addr[2] = AB8500_SENSOR_BTEMP_BALL;
209
+ data->gpadc_addr[3] = AB8500_SENSOR_BAT_CTRL;
193210 data->monitored_sensors = NUM_MONITORED_SENSORS;
194211
195212 data->ops.read_sensor = ab8500_read_sensor;