Lines Matching +full:temp +full:- +full:alarm
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 */
74 long temp; member
87 /* This array maps from GEN2 alarm state to GEN1 alarm stage */
95 ret = regmap_read(chip->map, chip->base + addr, &val); in qpnp_tm_read()
105 return regmap_write(chip->map, chip->base + addr, data); in qpnp_tm_write()
109 * qpnp_tm_decode_temp() - return temperature in mC corresponding to the
110 * specified over-temperature stage
112 * @stage: Over-temperature stage
118 if (!chip->temp_map || chip->thresh >= THRESH_COUNT || stage == 0 || in qpnp_tm_decode_temp()
122 return (*chip->temp_map)[chip->thresh][stage - 1]; in qpnp_tm_decode_temp()
126 * qpnp_tm_get_temp_stage() - return over-temperature stage
140 if (chip->subtype == QPNP_TM_SUBTYPE_GEN1) in qpnp_tm_get_temp_stage()
149 * This function updates the internal temp value based on the
157 WARN_ON(!mutex_is_locked(&chip->lock)); in qpnp_tm_update_temp_no_adc()
164 if (chip->subtype == QPNP_TM_SUBTYPE_GEN1) { in qpnp_tm_update_temp_no_adc()
166 stage_old = chip->stage; in qpnp_tm_update_temp_no_adc()
169 stage_old = alarm_state_map[chip->stage]; in qpnp_tm_update_temp_no_adc()
174 chip->temp = qpnp_tm_decode_temp(chip, stage_new) in qpnp_tm_update_temp_no_adc()
178 chip->temp = qpnp_tm_decode_temp(chip, stage_new + 1) in qpnp_tm_update_temp_no_adc()
179 - TEMP_STAGE_HYSTERESIS; in qpnp_tm_update_temp_no_adc()
182 chip->stage = stage; in qpnp_tm_update_temp_no_adc()
187 static int qpnp_tm_get_temp(struct thermal_zone_device *tz, int *temp) in qpnp_tm_get_temp() argument
192 if (!temp) in qpnp_tm_get_temp()
193 return -EINVAL; in qpnp_tm_get_temp()
195 if (!chip->initialized) { in qpnp_tm_get_temp()
196 *temp = DEFAULT_TEMP; in qpnp_tm_get_temp()
200 if (!chip->adc) { in qpnp_tm_get_temp()
201 mutex_lock(&chip->lock); in qpnp_tm_get_temp()
203 mutex_unlock(&chip->lock); in qpnp_tm_get_temp()
207 ret = iio_read_channel_processed(chip->adc, &mili_celsius); in qpnp_tm_get_temp()
211 chip->temp = mili_celsius; in qpnp_tm_get_temp()
214 *temp = chip->temp; in qpnp_tm_get_temp()
220 int temp) in qpnp_tm_update_critical_trip_temp() argument
222 long stage2_threshold_min = (*chip->temp_map)[THRESH_MIN][1]; in qpnp_tm_update_critical_trip_temp()
223 long stage2_threshold_max = (*chip->temp_map)[THRESH_MAX][1]; in qpnp_tm_update_critical_trip_temp()
227 WARN_ON(!mutex_is_locked(&chip->lock)); in qpnp_tm_update_critical_trip_temp()
235 if (temp == THERMAL_TEMP_INVALID || in qpnp_tm_update_critical_trip_temp()
236 temp < stage2_threshold_min) { in qpnp_tm_update_critical_trip_temp()
237 chip->thresh = THRESH_MIN; in qpnp_tm_update_critical_trip_temp()
241 if (temp <= stage2_threshold_max) { in qpnp_tm_update_critical_trip_temp()
242 chip->thresh = THRESH_MAX - in qpnp_tm_update_critical_trip_temp()
243 ((stage2_threshold_max - temp) / in qpnp_tm_update_critical_trip_temp()
247 chip->thresh = THRESH_MAX; in qpnp_tm_update_critical_trip_temp()
249 if (chip->adc) in qpnp_tm_update_critical_trip_temp()
252 dev_warn(chip->dev, in qpnp_tm_update_critical_trip_temp()
254 temp, stage2_threshold_max, stage2_threshold_max); in qpnp_tm_update_critical_trip_temp()
258 reg |= chip->thresh; in qpnp_tm_update_critical_trip_temp()
265 static int qpnp_tm_set_trip_temp(struct thermal_zone_device *tz, int trip_id, int temp) in qpnp_tm_set_trip_temp() argument
271 ret = __thermal_zone_get_trip(chip->tz_dev, trip_id, &trip); in qpnp_tm_set_trip_temp()
278 mutex_lock(&chip->lock); in qpnp_tm_set_trip_temp()
279 ret = qpnp_tm_update_critical_trip_temp(chip, temp); in qpnp_tm_set_trip_temp()
280 mutex_unlock(&chip->lock); in qpnp_tm_set_trip_temp()
294 thermal_zone_device_update(chip->tz_dev, THERMAL_EVENT_UNSPECIFIED); in qpnp_tm_isr()
304 for (i = 0; i < thermal_zone_get_num_trips(chip->tz_dev); i++) { in qpnp_tm_get_critical_trip_temp()
306 ret = thermal_zone_get_trip(chip->tz_dev, i, &trip); in qpnp_tm_get_critical_trip_temp()
318 * This function initializes the internal temp value based on only the
329 mutex_lock(&chip->lock); in qpnp_tm_init()
335 chip->thresh = reg & SHUTDOWN_CTRL1_THRESHOLD_MASK; in qpnp_tm_init()
336 chip->temp = DEFAULT_TEMP; in qpnp_tm_init()
341 chip->stage = ret; in qpnp_tm_init()
343 stage = chip->subtype == QPNP_TM_SUBTYPE_GEN1 in qpnp_tm_init()
344 ? chip->stage : alarm_state_map[chip->stage]; in qpnp_tm_init()
347 chip->temp = qpnp_tm_decode_temp(chip, stage); in qpnp_tm_init()
349 mutex_unlock(&chip->lock); in qpnp_tm_init()
353 mutex_lock(&chip->lock); in qpnp_tm_init()
359 /* Enable the thermal alarm PMIC module in always-on mode. */ in qpnp_tm_init()
363 chip->initialized = true; in qpnp_tm_init()
366 mutex_unlock(&chip->lock); in qpnp_tm_init()
378 node = pdev->dev.of_node; in qpnp_tm_probe()
380 chip = devm_kzalloc(&pdev->dev, sizeof(*chip), GFP_KERNEL); in qpnp_tm_probe()
382 return -ENOMEM; in qpnp_tm_probe()
384 dev_set_drvdata(&pdev->dev, chip); in qpnp_tm_probe()
385 chip->dev = &pdev->dev; in qpnp_tm_probe()
387 mutex_init(&chip->lock); in qpnp_tm_probe()
389 chip->map = dev_get_regmap(pdev->dev.parent, NULL); in qpnp_tm_probe()
390 if (!chip->map) in qpnp_tm_probe()
391 return -ENXIO; in qpnp_tm_probe()
402 chip->adc = devm_iio_channel_get(&pdev->dev, "thermal"); in qpnp_tm_probe()
403 if (IS_ERR(chip->adc)) { in qpnp_tm_probe()
404 ret = PTR_ERR(chip->adc); in qpnp_tm_probe()
405 chip->adc = NULL; in qpnp_tm_probe()
406 if (ret == -EPROBE_DEFER) in qpnp_tm_probe()
410 chip->base = res; in qpnp_tm_probe()
414 return dev_err_probe(&pdev->dev, ret, in qpnp_tm_probe()
419 return dev_err_probe(&pdev->dev, ret, in qpnp_tm_probe()
424 return dev_err_probe(&pdev->dev, ret, in qpnp_tm_probe()
429 dev_err(&pdev->dev, "invalid type 0x%02x or subtype 0x%02x\n", in qpnp_tm_probe()
431 return -ENODEV; in qpnp_tm_probe()
434 chip->subtype = subtype; in qpnp_tm_probe()
436 chip->temp_map = &temp_map_gen2_v1; in qpnp_tm_probe()
438 chip->temp_map = &temp_map_gen1; in qpnp_tm_probe()
445 chip->tz_dev = devm_thermal_of_zone_register( in qpnp_tm_probe()
446 &pdev->dev, 0, chip, &qpnp_tm_sensor_ops); in qpnp_tm_probe()
447 if (IS_ERR(chip->tz_dev)) in qpnp_tm_probe()
448 return dev_err_probe(&pdev->dev, PTR_ERR(chip->tz_dev), in qpnp_tm_probe()
453 return dev_err_probe(&pdev->dev, ret, "init failed\n"); in qpnp_tm_probe()
455 devm_thermal_add_hwmon_sysfs(&pdev->dev, chip->tz_dev); in qpnp_tm_probe()
457 ret = devm_request_threaded_irq(&pdev->dev, irq, NULL, qpnp_tm_isr, in qpnp_tm_probe()
458 IRQF_ONESHOT, node->name, chip); in qpnp_tm_probe()
462 thermal_zone_device_update(chip->tz_dev, THERMAL_EVENT_UNSPECIFIED); in qpnp_tm_probe()
468 { .compatible = "qcom,spmi-temp-alarm" },
475 .name = "spmi-temp-alarm",
482 MODULE_ALIAS("platform:spmi-temp-alarm");
483 MODULE_DESCRIPTION("QPNP PMIC Temperature Alarm driver");