-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
thermal: qcom: tsens-8996: Add support for 8996 family of SoCs
The TSENS controller in 8996 family of SoCs is capable of converting the ADC code outputs to real temperature values (in decidegree Celsius). It can also be programmed to provide raw ADC code, but the secure software on 8996 programs it to provide real temperatures and also does the needed calibrations. We check the valid bit to ensure valid data is read by the AHB master. And the spec recommends the below algorithm to read data 3 consecutive times, which takes care of the worst case delay taken to propagate the updated data to the register. Signed-off-by: Rajendra Nayak <rnayak@codeaurora.org> Signed-off-by: Eduardo Valentin <edubezval@gmail.com> Signed-off-by: Zhang Rui <rui.zhang@intel.com>
- Loading branch information
Rajendra Nayak
authored and
Zhang Rui
committed
Sep 27, 2016
1 parent
20d4fd8
commit d059c73
Showing
4 changed files
with
89 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
obj-$(CONFIG_QCOM_TSENS) += qcom_tsens.o | ||
qcom_tsens-y += tsens.o tsens-common.o tsens-8916.o tsens-8974.o tsens-8960.o | ||
qcom_tsens-y += tsens.o tsens-common.o tsens-8916.o tsens-8974.o tsens-8960.o tsens-8996.o |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/* | ||
* Copyright (c) 2015, The Linux Foundation. All rights reserved. | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License version 2 and | ||
* only version 2 as published by the Free Software Foundation. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
*/ | ||
|
||
#include <linux/platform_device.h> | ||
#include <linux/regmap.h> | ||
#include "tsens.h" | ||
|
||
#define STATUS_OFFSET 0x10a0 | ||
#define LAST_TEMP_MASK 0xfff | ||
#define STATUS_VALID_BIT BIT(21) | ||
#define CODE_SIGN_BIT BIT(11) | ||
|
||
static int get_temp_8996(struct tsens_device *tmdev, int id, int *temp) | ||
{ | ||
struct tsens_sensor *s = &tmdev->sensor[id]; | ||
u32 code; | ||
unsigned int sensor_addr; | ||
int last_temp = 0, last_temp2 = 0, last_temp3 = 0, ret; | ||
|
||
sensor_addr = STATUS_OFFSET + s->hw_id * 4; | ||
ret = regmap_read(tmdev->map, sensor_addr, &code); | ||
if (ret) | ||
return ret; | ||
last_temp = code & LAST_TEMP_MASK; | ||
if (code & STATUS_VALID_BIT) | ||
goto done; | ||
|
||
/* Try a second time */ | ||
ret = regmap_read(tmdev->map, sensor_addr, &code); | ||
if (ret) | ||
return ret; | ||
if (code & STATUS_VALID_BIT) { | ||
last_temp = code & LAST_TEMP_MASK; | ||
goto done; | ||
} else { | ||
last_temp2 = code & LAST_TEMP_MASK; | ||
} | ||
|
||
/* Try a third/last time */ | ||
ret = regmap_read(tmdev->map, sensor_addr, &code); | ||
if (ret) | ||
return ret; | ||
if (code & STATUS_VALID_BIT) { | ||
last_temp = code & LAST_TEMP_MASK; | ||
goto done; | ||
} else { | ||
last_temp3 = code & LAST_TEMP_MASK; | ||
} | ||
|
||
if (last_temp == last_temp2) | ||
last_temp = last_temp2; | ||
else if (last_temp2 == last_temp3) | ||
last_temp = last_temp3; | ||
done: | ||
/* Code sign bit is the sign extension for a negative value */ | ||
if (last_temp & CODE_SIGN_BIT) | ||
last_temp |= ~CODE_SIGN_BIT; | ||
|
||
/* Temperatures are in deciCelicius */ | ||
*temp = last_temp * 100; | ||
|
||
return 0; | ||
} | ||
|
||
const struct tsens_ops ops_8996 = { | ||
.init = init_common, | ||
.get_temp = get_temp_8996, | ||
}; | ||
|
||
const struct tsens_data data_8996 = { | ||
.num_sensors = 13, | ||
.ops = &ops_8996, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters