| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * Copyright (C) ST-Ericsson 2010 - 2013 |
|---|
| 3 | 4 | * Author: Martin Persson <martin.persson@stericsson.com> |
|---|
| 4 | 5 | * Hongbo Zhang <hongbo.zhang@linaro.org> |
|---|
| 5 | | - * License Terms: GNU General Public License v2 |
|---|
| 6 | 6 | * |
|---|
| 7 | 7 | * When the AB8500 thermal warning temperature is reached (threshold cannot |
|---|
| 8 | 8 | * be changed by SW), an interrupt is set, and if no further action is taken |
|---|
| .. | .. |
|---|
| 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; |
|---|
| .. | .. |
|---|
| 40 | 44 | }; |
|---|
| 41 | 45 | |
|---|
| 42 | 46 | struct ab8500_temp { |
|---|
| 43 | | - struct ab8500_gpadc *gpadc; |
|---|
| 47 | + struct iio_channel *aux1; |
|---|
| 48 | + struct iio_channel *aux2; |
|---|
| 44 | 49 | struct ab8500_btemp *btemp; |
|---|
| 45 | 50 | struct delayed_work power_off_work; |
|---|
| 46 | 51 | struct ab8500_gpadc_cfg cfg; |
|---|
| .. | .. |
|---|
| 82 | 87 | int voltage, ret; |
|---|
| 83 | 88 | struct ab8500_temp *ab8500_data = data->plat_data; |
|---|
| 84 | 89 | |
|---|
| 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) { |
|---|
| 88 | 91 | *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; |
|---|
| 94 | 105 | ret = ab8500_voltage_to_temp(&ab8500_data->cfg, voltage, temp); |
|---|
| 95 | 106 | if (ret < 0) |
|---|
| 96 | 107 | return ret; |
|---|
| .. | .. |
|---|
| 164 | 175 | if (!ab8500_data) |
|---|
| 165 | 176 | return -ENOMEM; |
|---|
| 166 | 177 | |
|---|
| 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 | | - |
|---|
| 171 | 178 | ab8500_data->btemp = ab8500_btemp_get(); |
|---|
| 172 | 179 | if (IS_ERR(ab8500_data->btemp)) |
|---|
| 173 | 180 | return PTR_ERR(ab8500_data->btemp); |
|---|
| .. | .. |
|---|
| 181 | 188 | ab8500_data->cfg.tbl_sz = ab8500_temp_tbl_a_size; |
|---|
| 182 | 189 | |
|---|
| 183 | 190 | 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 | + } |
|---|
| 184 | 205 | |
|---|
| 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; |
|---|
| 193 | 210 | data->monitored_sensors = NUM_MONITORED_SENSORS; |
|---|
| 194 | 211 | |
|---|
| 195 | 212 | data->ops.read_sensor = ab8500_read_sensor; |
|---|