Lines Matching +full:resistance +full:- +full:temp +full:- +full:table
1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (C) ST-Ericsson 2010 - 2013
17 #include <linux/hwmon-sysfs.h>
19 #include <linux/mfd/abx500/ab8500-bm.h>
57 * VCC----[ R_up ]-----[ NTC ]----GND
58 * where R_up is pull-up resistance, and GPADC measures voltage on NTC.
59 * and res_to_temp table is strictly sorted by falling resistance values.
62 int v_ntc, int *temp) in ab8500_voltage_to_temp() argument
64 int r_ntc, i = 0, tbl_sz = cfg->tbl_sz; in ab8500_voltage_to_temp()
65 const struct abx500_res_to_temp *tbl = cfg->temp_tbl; in ab8500_voltage_to_temp()
67 if (cfg->vcc < 0 || v_ntc >= cfg->vcc) in ab8500_voltage_to_temp()
68 return -EINVAL; in ab8500_voltage_to_temp()
70 r_ntc = v_ntc * cfg->r_up / (cfg->vcc - v_ntc); in ab8500_voltage_to_temp()
71 if (r_ntc > tbl[0].resist || r_ntc < tbl[tbl_sz - 1].resist) in ab8500_voltage_to_temp()
72 return -EINVAL; in ab8500_voltage_to_temp()
75 i < tbl_sz - 2) in ab8500_voltage_to_temp()
78 /* return milli-Celsius */ in ab8500_voltage_to_temp()
79 *temp = tbl[i].temp * 1000 + ((tbl[i + 1].temp - tbl[i].temp) * 1000 * in ab8500_voltage_to_temp()
80 (r_ntc - tbl[i].resist)) / (tbl[i + 1].resist - tbl[i].resist); in ab8500_voltage_to_temp()
85 static int ab8500_read_sensor(struct abx500_temp *data, u8 sensor, int *temp) in ab8500_read_sensor() argument
88 struct ab8500_temp *ab8500_data = data->plat_data; in ab8500_read_sensor()
91 *temp = ab8500_btemp_get_temp(ab8500_data->btemp); in ab8500_read_sensor()
93 *temp = ab8500_btemp_get_batctrl_temp(ab8500_data->btemp); in ab8500_read_sensor()
95 ret = iio_read_channel_processed(ab8500_data->aux1, &voltage); in ab8500_read_sensor()
98 ret = ab8500_voltage_to_temp(&ab8500_data->cfg, voltage, temp); in ab8500_read_sensor()
102 ret = iio_read_channel_processed(ab8500_data->aux2, &voltage); in ab8500_read_sensor()
105 ret = ab8500_voltage_to_temp(&ab8500_data->cfg, voltage, temp); in ab8500_read_sensor()
117 struct abx500_temp *abx500_data = ab8500_data->abx500_data; in ab8500_thermal_power_off()
119 dev_warn(&abx500_data->pdev->dev, "Power off due to critical temp\n"); in ab8500_thermal_power_off()
135 int index = attr->index; in ab8500_show_label()
151 return -EINVAL; in ab8500_show_label()
159 struct ab8500_temp *ab8500_data = data->plat_data; in ab8500_temp_irq_handler()
161 dev_warn(&data->pdev->dev, "Power off in %d s\n", in ab8500_temp_irq_handler()
164 schedule_delayed_work(&ab8500_data->power_off_work, in ab8500_temp_irq_handler()
173 ab8500_data = devm_kzalloc(&data->pdev->dev, sizeof(*ab8500_data), in abx500_hwmon_init()
176 return -ENOMEM; in abx500_hwmon_init()
178 ab8500_data->btemp = ab8500_btemp_get(); in abx500_hwmon_init()
179 if (IS_ERR(ab8500_data->btemp)) in abx500_hwmon_init()
180 return PTR_ERR(ab8500_data->btemp); in abx500_hwmon_init()
182 INIT_DELAYED_WORK(&ab8500_data->power_off_work, in abx500_hwmon_init()
185 ab8500_data->cfg.vcc = THERMAL_VCC; in abx500_hwmon_init()
186 ab8500_data->cfg.r_up = PULL_UP_RESISTOR; in abx500_hwmon_init()
187 ab8500_data->cfg.temp_tbl = ab8500_temp_tbl_a_thermistor; in abx500_hwmon_init()
188 ab8500_data->cfg.tbl_sz = ab8500_temp_tbl_a_size; in abx500_hwmon_init()
190 data->plat_data = ab8500_data; in abx500_hwmon_init()
191 ab8500_data->aux1 = devm_iio_channel_get(&data->pdev->dev, "aux1"); in abx500_hwmon_init()
192 if (IS_ERR(ab8500_data->aux1)) { in abx500_hwmon_init()
193 if (PTR_ERR(ab8500_data->aux1) == -ENODEV) in abx500_hwmon_init()
194 return -EPROBE_DEFER; in abx500_hwmon_init()
195 dev_err(&data->pdev->dev, "failed to get AUX1 ADC channel\n"); in abx500_hwmon_init()
196 return PTR_ERR(ab8500_data->aux1); in abx500_hwmon_init()
198 ab8500_data->aux2 = devm_iio_channel_get(&data->pdev->dev, "aux2"); in abx500_hwmon_init()
199 if (IS_ERR(ab8500_data->aux2)) { in abx500_hwmon_init()
200 if (PTR_ERR(ab8500_data->aux2) == -ENODEV) in abx500_hwmon_init()
201 return -EPROBE_DEFER; in abx500_hwmon_init()
202 dev_err(&data->pdev->dev, "failed to get AUX2 ADC channel\n"); in abx500_hwmon_init()
203 return PTR_ERR(ab8500_data->aux2); in abx500_hwmon_init()
206 data->gpadc_addr[0] = AB8500_SENSOR_AUX1; in abx500_hwmon_init()
207 data->gpadc_addr[1] = AB8500_SENSOR_AUX2; in abx500_hwmon_init()
208 data->gpadc_addr[2] = AB8500_SENSOR_BTEMP_BALL; in abx500_hwmon_init()
209 data->gpadc_addr[3] = AB8500_SENSOR_BAT_CTRL; in abx500_hwmon_init()
210 data->monitored_sensors = NUM_MONITORED_SENSORS; in abx500_hwmon_init()
212 data->ops.read_sensor = ab8500_read_sensor; in abx500_hwmon_init()
213 data->ops.irq_handler = ab8500_temp_irq_handler; in abx500_hwmon_init()
214 data->ops.show_name = ab8500_show_name; in abx500_hwmon_init()
215 data->ops.show_label = ab8500_show_label; in abx500_hwmon_init()
216 data->ops.is_visible = NULL; in abx500_hwmon_init()