Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

hwmon: ab8500: Convert to IIO ADC

This switches the AB8500 hardware monitor driver to using
the standard IIO ADC channel lookup and conversion routines.

Acked-by: Guenter Roeck <linux@roeck-us.net>
Acked-by: Jonathan Cameron <jic23@kernel.org>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

Linus Walleij and committed by
Jonathan Cameron
d17e86cb 1e82623c

+43 -25
+2 -1
drivers/hwmon/Kconfig
··· 40 40 41 41 config SENSORS_AB8500 42 42 tristate "AB8500 thermal monitoring" 43 - depends on AB8500_GPADC && AB8500_BM 43 + depends on AB8500_GPADC && AB8500_BM && (IIO = y) 44 + default n 44 45 help 45 46 If you say yes here you get support for the thermal sensor part 46 47 of the AB8500 chip. The driver includes thermal management for
+41 -24
drivers/hwmon/ab8500.c
··· 17 17 #include <linux/hwmon-sysfs.h> 18 18 #include <linux/mfd/abx500.h> 19 19 #include <linux/mfd/abx500/ab8500-bm.h> 20 - #include <linux/mfd/abx500/ab8500-gpadc.h> 21 20 #include <linux/module.h> 22 21 #include <linux/platform_device.h> 23 22 #include <linux/power/ab8500.h> 24 23 #include <linux/reboot.h> 25 24 #include <linux/slab.h> 26 25 #include <linux/sysfs.h> 26 + #include <linux/iio/consumer.h> 27 27 #include "abx500.h" 28 28 29 29 #define DEFAULT_POWER_OFF_DELAY (HZ * 10) 30 30 #define THERMAL_VCC 1800 31 31 #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 34 38 35 39 struct ab8500_gpadc_cfg { 36 40 const struct abx500_res_to_temp *temp_tbl; ··· 44 40 }; 45 41 46 42 struct ab8500_temp { 47 - struct ab8500_gpadc *gpadc; 43 + struct iio_channel *aux1; 44 + struct iio_channel *aux2; 48 45 struct ab8500_btemp *btemp; 49 46 struct delayed_work power_off_work; 50 47 struct ab8500_gpadc_cfg cfg; ··· 87 82 int voltage, ret; 88 83 struct ab8500_temp *ab8500_data = data->plat_data; 89 84 90 - if (sensor == BAT_CTRL) { 91 - *temp = ab8500_btemp_get_batctrl_temp(ab8500_data->btemp); 92 - } else if (sensor == BTEMP_BALL) { 85 + if (sensor == AB8500_SENSOR_BTEMP_BALL) { 93 86 *temp = ab8500_btemp_get_temp(ab8500_data->btemp); 94 - } else { 95 - voltage = ab8500_gpadc_convert(ab8500_data->gpadc, sensor); 96 - if (voltage < 0) 97 - return voltage; 98 - 87 + } else if (sensor == AB8500_SENSOR_BAT_CTRL) { 88 + *temp = ab8500_btemp_get_batctrl_temp(ab8500_data->btemp); 89 + } else if (sensor == AB8500_SENSOR_AUX1) { 90 + ret = iio_read_channel_processed(ab8500_data->aux1, &voltage); 91 + if (ret < 0) 92 + return ret; 93 + ret = ab8500_voltage_to_temp(&ab8500_data->cfg, voltage, temp); 94 + if (ret < 0) 95 + return ret; 96 + } else if (sensor == AB8500_SENSOR_AUX2) { 97 + ret = iio_read_channel_processed(ab8500_data->aux2, &voltage); 98 + if (ret < 0) 99 + return ret; 99 100 ret = ab8500_voltage_to_temp(&ab8500_data->cfg, voltage, temp); 100 101 if (ret < 0) 101 102 return ret; ··· 175 164 if (!ab8500_data) 176 165 return -ENOMEM; 177 166 178 - ab8500_data->gpadc = ab8500_gpadc_get("ab8500-gpadc.0"); 179 - if (IS_ERR(ab8500_data->gpadc)) 180 - return PTR_ERR(ab8500_data->gpadc); 181 - 182 167 ab8500_data->btemp = ab8500_btemp_get(); 183 168 if (IS_ERR(ab8500_data->btemp)) 184 169 return PTR_ERR(ab8500_data->btemp); ··· 188 181 ab8500_data->cfg.tbl_sz = ab8500_temp_tbl_a_size; 189 182 190 183 data->plat_data = ab8500_data; 184 + ab8500_data->aux1 = devm_iio_channel_get(&data->pdev->dev, "aux1"); 185 + if (IS_ERR(ab8500_data->aux1)) { 186 + if (PTR_ERR(ab8500_data->aux1) == -ENODEV) 187 + return -EPROBE_DEFER; 188 + dev_err(&data->pdev->dev, "failed to get AUX1 ADC channel\n"); 189 + return PTR_ERR(ab8500_data->aux1); 190 + } 191 + ab8500_data->aux2 = devm_iio_channel_get(&data->pdev->dev, "aux2"); 192 + if (IS_ERR(ab8500_data->aux2)) { 193 + if (PTR_ERR(ab8500_data->aux2) == -ENODEV) 194 + return -EPROBE_DEFER; 195 + dev_err(&data->pdev->dev, "failed to get AUX2 ADC channel\n"); 196 + return PTR_ERR(ab8500_data->aux2); 197 + } 191 198 192 - /* 193 - * ADC_AUX1 and ADC_AUX2, connected to external NTC 194 - * BTEMP_BALL and BAT_CTRL, fixed usage 195 - */ 196 - data->gpadc_addr[0] = ADC_AUX1; 197 - data->gpadc_addr[1] = ADC_AUX2; 198 - data->gpadc_addr[2] = BTEMP_BALL; 199 - data->gpadc_addr[3] = BAT_CTRL; 199 + data->gpadc_addr[0] = AB8500_SENSOR_AUX1; 200 + data->gpadc_addr[1] = AB8500_SENSOR_AUX2; 201 + data->gpadc_addr[2] = AB8500_SENSOR_BTEMP_BALL; 202 + data->gpadc_addr[3] = AB8500_SENSOR_BAT_CTRL; 200 203 data->monitored_sensors = NUM_MONITORED_SENSORS; 201 204 202 205 data->ops.read_sensor = ab8500_read_sensor;