Source
/*
* Junction temperature thermal driver for Maxim Max77620.
*
* Copyright (c) 2016, NVIDIA CORPORATION. All rights reserved.
*
* Author: Laxman Dewangan <ldewangan@nvidia.com>
* Mallikarjun Kasoju <mkasoju@nvidia.com>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*/
struct max77620_therm_info {
struct device *dev;
struct regmap *rmap;
struct thermal_zone_device *tz_device;
int irq_tjalarm1;
int irq_tjalarm2;
};
/**
* max77620_thermal_read_temp: Read PMIC die temperatue.
* @data: Device specific data.
* temp: Temperature in millidegrees Celsius
*
* The actual temperature of PMIC die is not available from PMIC.
* PMIC only tells the status if it has crossed or not the threshold level
* of 120degC or 140degC.
* If threshold has not been crossed then assume die temperature as 100degC
* else 120degC or 140deG based on the PMIC die temp threshold status.
*
* Return 0 on success otherwise error number to show reason of failure.
*/
static int max77620_thermal_read_temp(void *data, int *temp)
{
struct max77620_therm_info *mtherm = data;
unsigned int val;
int ret;
ret = regmap_read(mtherm->rmap, MAX77620_REG_STATLBT, &val);
if (ret < 0) {
dev_err(mtherm->dev, "Failed to read STATLBT: %d\n", ret);
return ret;
}
if (val & MAX77620_IRQ_TJALRM2_MASK)
*temp = MAX77620_TJALARM2_TEMP;