Lines Matching +full:adc +full:- +full:use +full:- +full:res
1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (c) 2011-2015, 2017, 2020, The Linux Foundation. All rights reserved.
44 /* Over-temperature trip point values in mC */
66 /* Temperature in Milli Celsius reported during stage 0 if no ADC is present */
82 struct iio_channel *adc; member
94 ret = regmap_read(chip->map, chip->base + addr, &val); in qpnp_tm_read()
104 return regmap_write(chip->map, chip->base + addr, data); in qpnp_tm_write()
108 * qpnp_tm_decode_temp() - return temperature in mC corresponding to the
109 * specified over-temperature stage
111 * @stage: Over-temperature stage
117 if (!chip->temp_map || chip->thresh >= THRESH_COUNT || stage == 0 || in qpnp_tm_decode_temp()
121 return (*chip->temp_map)[chip->thresh][stage - 1]; in qpnp_tm_decode_temp()
125 * qpnp_tm_get_temp_stage() - return over-temperature stage
139 if (chip->subtype == QPNP_TM_SUBTYPE_GEN1) in qpnp_tm_get_temp_stage()
156 WARN_ON(!mutex_is_locked(&chip->lock)); in qpnp_tm_update_temp_no_adc()
163 if (chip->subtype == QPNP_TM_SUBTYPE_GEN1) { in qpnp_tm_update_temp_no_adc()
165 stage_old = chip->stage; in qpnp_tm_update_temp_no_adc()
168 stage_old = alarm_state_map[chip->stage]; in qpnp_tm_update_temp_no_adc()
172 /* increasing stage, use lower bound */ in qpnp_tm_update_temp_no_adc()
173 chip->temp = qpnp_tm_decode_temp(chip, stage_new) in qpnp_tm_update_temp_no_adc()
176 /* decreasing stage, use upper bound */ in qpnp_tm_update_temp_no_adc()
177 chip->temp = qpnp_tm_decode_temp(chip, stage_new + 1) in qpnp_tm_update_temp_no_adc()
178 - TEMP_STAGE_HYSTERESIS; in qpnp_tm_update_temp_no_adc()
181 chip->stage = stage; in qpnp_tm_update_temp_no_adc()
192 return -EINVAL; in qpnp_tm_get_temp()
194 if (!chip->initialized) { in qpnp_tm_get_temp()
199 if (!chip->adc) { in qpnp_tm_get_temp()
200 mutex_lock(&chip->lock); in qpnp_tm_get_temp()
202 mutex_unlock(&chip->lock); in qpnp_tm_get_temp()
206 ret = iio_read_channel_processed(chip->adc, &mili_celsius); in qpnp_tm_get_temp()
210 chip->temp = mili_celsius; in qpnp_tm_get_temp()
213 *temp = chip->temp; in qpnp_tm_get_temp()
221 long stage2_threshold_min = (*chip->temp_map)[THRESH_MIN][1]; in qpnp_tm_update_critical_trip_temp()
222 long stage2_threshold_max = (*chip->temp_map)[THRESH_MAX][1]; in qpnp_tm_update_critical_trip_temp()
226 WARN_ON(!mutex_is_locked(&chip->lock)); in qpnp_tm_update_critical_trip_temp()
236 chip->thresh = THRESH_MIN; in qpnp_tm_update_critical_trip_temp()
241 chip->thresh = THRESH_MAX - in qpnp_tm_update_critical_trip_temp()
242 ((stage2_threshold_max - temp) / in qpnp_tm_update_critical_trip_temp()
246 chip->thresh = THRESH_MAX; in qpnp_tm_update_critical_trip_temp()
248 if (chip->adc) in qpnp_tm_update_critical_trip_temp()
251 dev_warn(chip->dev, in qpnp_tm_update_critical_trip_temp()
252 …"No ADC is configured and critical temperature %d mC is above the maximum stage 2 threshold of %ld… in qpnp_tm_update_critical_trip_temp()
257 reg |= chip->thresh; in qpnp_tm_update_critical_trip_temp()
270 if (trip->type != THERMAL_TRIP_CRITICAL) in qpnp_tm_set_trip_temp()
273 mutex_lock(&chip->lock); in qpnp_tm_set_trip_temp()
275 mutex_unlock(&chip->lock); in qpnp_tm_set_trip_temp()
289 thermal_zone_device_update(chip->tz_dev, THERMAL_EVENT_UNSPECIFIED); in qpnp_tm_isr()
306 mutex_lock(&chip->lock); in qpnp_tm_init()
312 chip->thresh = reg & SHUTDOWN_CTRL1_THRESHOLD_MASK; in qpnp_tm_init()
313 chip->temp = DEFAULT_TEMP; in qpnp_tm_init()
318 chip->stage = ret; in qpnp_tm_init()
320 stage = chip->subtype == QPNP_TM_SUBTYPE_GEN1 in qpnp_tm_init()
321 ? chip->stage : alarm_state_map[chip->stage]; in qpnp_tm_init()
324 chip->temp = qpnp_tm_decode_temp(chip, stage); in qpnp_tm_init()
326 mutex_unlock(&chip->lock); in qpnp_tm_init()
328 ret = thermal_zone_get_crit_temp(chip->tz_dev, &crit_temp); in qpnp_tm_init()
332 mutex_lock(&chip->lock); in qpnp_tm_init()
338 /* Enable the thermal alarm PMIC module in always-on mode. */ in qpnp_tm_init()
342 chip->initialized = true; in qpnp_tm_init()
345 mutex_unlock(&chip->lock); in qpnp_tm_init()
354 u32 res; in qpnp_tm_probe() local
357 node = pdev->dev.of_node; in qpnp_tm_probe()
359 chip = devm_kzalloc(&pdev->dev, sizeof(*chip), GFP_KERNEL); in qpnp_tm_probe()
361 return -ENOMEM; in qpnp_tm_probe()
363 dev_set_drvdata(&pdev->dev, chip); in qpnp_tm_probe()
364 chip->dev = &pdev->dev; in qpnp_tm_probe()
366 mutex_init(&chip->lock); in qpnp_tm_probe()
368 chip->map = dev_get_regmap(pdev->dev.parent, NULL); in qpnp_tm_probe()
369 if (!chip->map) in qpnp_tm_probe()
370 return -ENXIO; in qpnp_tm_probe()
372 ret = of_property_read_u32(node, "reg", &res); in qpnp_tm_probe()
380 /* ADC based measurements are optional */ in qpnp_tm_probe()
381 chip->adc = devm_iio_channel_get(&pdev->dev, "thermal"); in qpnp_tm_probe()
382 if (IS_ERR(chip->adc)) { in qpnp_tm_probe()
383 ret = PTR_ERR(chip->adc); in qpnp_tm_probe()
384 chip->adc = NULL; in qpnp_tm_probe()
385 if (ret == -EPROBE_DEFER) in qpnp_tm_probe()
389 chip->base = res; in qpnp_tm_probe()
393 return dev_err_probe(&pdev->dev, ret, in qpnp_tm_probe()
398 return dev_err_probe(&pdev->dev, ret, in qpnp_tm_probe()
403 return dev_err_probe(&pdev->dev, ret, in qpnp_tm_probe()
408 dev_err(&pdev->dev, "invalid type 0x%02x or subtype 0x%02x\n", in qpnp_tm_probe()
410 return -ENODEV; in qpnp_tm_probe()
413 chip->subtype = subtype; in qpnp_tm_probe()
415 chip->temp_map = &temp_map_gen2_v1; in qpnp_tm_probe()
417 chip->temp_map = &temp_map_gen1; in qpnp_tm_probe()
424 chip->tz_dev = devm_thermal_of_zone_register( in qpnp_tm_probe()
425 &pdev->dev, 0, chip, &qpnp_tm_sensor_ops); in qpnp_tm_probe()
426 if (IS_ERR(chip->tz_dev)) in qpnp_tm_probe()
427 return dev_err_probe(&pdev->dev, PTR_ERR(chip->tz_dev), in qpnp_tm_probe()
432 return dev_err_probe(&pdev->dev, ret, "init failed\n"); in qpnp_tm_probe()
434 devm_thermal_add_hwmon_sysfs(&pdev->dev, chip->tz_dev); in qpnp_tm_probe()
436 ret = devm_request_threaded_irq(&pdev->dev, irq, NULL, qpnp_tm_isr, in qpnp_tm_probe()
437 IRQF_ONESHOT, node->name, chip); in qpnp_tm_probe()
441 thermal_zone_device_update(chip->tz_dev, THERMAL_EVENT_UNSPECIFIED); in qpnp_tm_probe()
447 { .compatible = "qcom,spmi-temp-alarm" },
454 .name = "spmi-temp-alarm",
461 MODULE_ALIAS("platform:spmi-temp-alarm");