2020-01-26 03:47:49 +00:00
|
|
|
--- a/drivers/thermal/qcom/tsens-ipq8064.c
|
|
|
|
+++ b/drivers/thermal/qcom/tsens-ipq8064.c
|
|
|
|
@@ -13,10 +13,12 @@
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/platform_device.h>
|
|
|
|
+#include <linux/err.h>
|
|
|
|
#include <linux/delay.h>
|
|
|
|
#include <linux/bitops.h>
|
|
|
|
#include <linux/regmap.h>
|
|
|
|
#include <linux/thermal.h>
|
|
|
|
+#include <linux/slab.h>
|
|
|
|
#include <linux/nvmem-consumer.h>
|
2020-01-26 03:32:45 +00:00
|
|
|
#include <linux/of_platform.h>
|
2020-01-26 03:47:49 +00:00
|
|
|
#include <linux/io.h>
|
2020-01-26 03:32:45 +00:00
|
|
|
@@ -211,9 +213,8 @@ static void tsens_scheduler_fn(struct wo
|
|
|
|
struct tsens_priv *priv = container_of(work, struct tsens_priv,
|
2020-01-26 03:47:49 +00:00
|
|
|
tsens_work);
|
|
|
|
unsigned int threshold, threshold_low, code, reg, sensor, mask;
|
|
|
|
- unsigned int sensor_addr;
|
|
|
|
bool upper_th_x, lower_th_x;
|
|
|
|
- int adc_code, ret;
|
|
|
|
+ int ret;
|
|
|
|
|
2020-01-26 03:32:45 +00:00
|
|
|
ret = regmap_read(priv->tm_map, STATUS_CNTL_8064, ®);
|
2020-01-26 03:47:49 +00:00
|
|
|
if (ret)
|
2020-01-26 03:32:45 +00:00
|
|
|
@@ -262,9 +263,8 @@ static void tsens_scheduler_fn(struct wo
|
2020-01-26 03:47:49 +00:00
|
|
|
if (upper_th_x || lower_th_x) {
|
|
|
|
/* Notify user space */
|
2020-01-26 03:32:45 +00:00
|
|
|
schedule_work(&priv->sensor[0].notify_work);
|
|
|
|
- regmap_read(priv->tm_map, sensor_addr, &adc_code);
|
2020-01-26 03:47:49 +00:00
|
|
|
pr_debug("Trigger (%d degrees) for sensor %d\n",
|
2020-01-26 03:32:45 +00:00
|
|
|
- code_to_degC(adc_code, &priv->sensor[0]), 0);
|
|
|
|
+ code_to_degC(code, &priv->sensor[0]), 0);
|
2020-01-26 03:47:49 +00:00
|
|
|
}
|
|
|
|
}
|
2020-01-26 03:32:45 +00:00
|
|
|
regmap_write(priv->tm_map, STATUS_CNTL_8064, reg & mask);
|
|
|
|
@@ -404,40 +404,55 @@ err_put_device:
|
|
|
|
static int calibrate_ipq8064(struct tsens_priv *priv)
|
2020-01-26 03:47:49 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
- char *data, *data_backup;
|
|
|
|
-
|
|
|
|
+ int ret = 0;
|
|
|
|
+ u8 *data, *data_backup;
|
2020-01-26 03:32:45 +00:00
|
|
|
+ struct device *dev = priv->dev;
|
|
|
|
ssize_t num_read = priv->num_sensors;
|
|
|
|
struct tsens_sensor *s = priv->sensor;
|
2020-01-26 03:47:49 +00:00
|
|
|
|
2020-01-26 03:32:45 +00:00
|
|
|
- data = qfprom_read(priv->dev, "calib");
|
2020-01-26 03:47:49 +00:00
|
|
|
+ data = qfprom_read(dev, "calib");
|
|
|
|
if (IS_ERR(data)) {
|
|
|
|
- pr_err("Calibration not found.\n");
|
|
|
|
- return PTR_ERR(data);
|
|
|
|
+ ret = PTR_ERR(data);
|
|
|
|
+ if (ret != -EPROBE_DEFER)
|
|
|
|
+ dev_err(dev, "Calibration not found.");
|
|
|
|
+ goto exit;
|
|
|
|
}
|
|
|
|
|
2020-01-26 03:32:45 +00:00
|
|
|
- data_backup = qfprom_read(priv->dev, "calib_backup");
|
2020-01-26 03:47:49 +00:00
|
|
|
+ data_backup = qfprom_read(dev, "calib_backup");
|
|
|
|
if (IS_ERR(data_backup)) {
|
|
|
|
- pr_err("Backup calibration not found.\n");
|
|
|
|
- return PTR_ERR(data_backup);
|
|
|
|
+ ret = PTR_ERR(data_backup);
|
|
|
|
+ if (ret != -EPROBE_DEFER)
|
|
|
|
+ dev_err(dev, "Backup Calibration not found.");
|
|
|
|
+ goto free_data;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < num_read; i++) {
|
|
|
|
s[i].calib_data = readb_relaxed(data + i);
|
|
|
|
- s[i].calib_data_backup = readb_relaxed(data_backup + i);
|
|
|
|
+
|
|
|
|
+ if (!s[i].calib_data) {
|
|
|
|
+ s[i].calib_data_backup = readb_relaxed(data_backup + i);
|
|
|
|
+
|
|
|
|
+ if (!s[i].calib_data_backup) {
|
|
|
|
+ dev_err(dev, "QFPROM TSENS calibration data not present");
|
|
|
|
+ ret = -ENODEV;
|
|
|
|
+ goto free_backup;
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- if (s[i].calib_data_backup)
|
|
|
|
s[i].calib_data = s[i].calib_data_backup;
|
|
|
|
- if (!s[i].calib_data) {
|
|
|
|
- pr_err("QFPROM TSENS calibration data not present\n");
|
|
|
|
- return -ENODEV;
|
|
|
|
}
|
|
|
|
+
|
|
|
|
s[i].slope = tsens_8064_slope[i];
|
|
|
|
s[i].offset = CAL_MDEGC - (s[i].calib_data * s[i].slope);
|
|
|
|
}
|
|
|
|
|
2020-01-26 03:32:45 +00:00
|
|
|
hw_init(priv);
|
2020-01-26 03:47:49 +00:00
|
|
|
|
|
|
|
- return 0;
|
|
|
|
+free_backup:
|
|
|
|
+ kfree(data_backup);
|
|
|
|
+free_data:
|
|
|
|
+ kfree(data);
|
|
|
|
+exit:
|
|
|
|
+ return ret;
|
|
|
|
}
|
|
|
|
|
2020-01-26 03:32:45 +00:00
|
|
|
static int get_temp_ipq8064(struct tsens_priv *priv, int id, int *temp)
|