(CR):[kane]:kernel: use thermal temperature as battery temp
authorzhixueyin <zhixueyin@huaqin.com>
Mon, 24 Dec 2018 02:35:20 +0000 (10:35 +0800)
committerlingsen1 <lingsen1@lenovo.com>
Sun, 7 Feb 2021 09:36:44 +0000 (17:36 +0800)
use thermal temperature as battery temp

Change-Id: I727feed181859b4e1b71e064d9316a443add2fc1

drivers/hwmon/ntc_thermistor.c
drivers/power/supply/s2mu106_fuelgauge.c
include/linux/platform_data/ntc_thermistor.h
include/linux/power/s2mu106_fuelgauge.h [changed mode: 0644->0755]

index b19a2e6e934755a0b4f9680526d707cb5cc4d19e..3f4ccdb682c4a5ddbf712b4906a86b7be8aabd06 100755 (executable)
@@ -258,6 +258,8 @@ struct ntc_data {
        int n_comp;
 };
 
+struct ntc_data *data_ntc = NULL;
+
 #if defined(CONFIG_OF) && IS_ENABLED(CONFIG_IIO)
 static int ntc_adc_iio_read(struct ntc_thermistor_platform_data *pdata)
 {
@@ -551,6 +553,27 @@ static ssize_t ntc_show_temp(struct device *dev,
        return sprintf(buf, "%d\n", get_temp_mc(data, ohm));
 }
 
+int ntc_show_batt_temp()
+{
+       int ohm;
+       int temp;
+
+       if (data_ntc == NULL) {
+               pr_err("%s data is NULL!\n", __func__);
+               return 250;
+       }
+       ohm = ntc_thermistor_get_ohm(data_ntc);
+       if (ohm < 0)
+               return ohm;
+       temp = get_temp_mc(data_ntc, ohm) / 100;
+       if (temp == BATT_NTC100K_ORIGINAL_TEMP) {
+               temp = BATT_NTC100K_NOW_TEMP;
+       }
+
+       return temp;
+}
+EXPORT_SYMBOL_GPL(ntc_show_batt_temp);
+
 static SENSOR_DEVICE_ATTR(temp1_type, S_IRUGO, ntc_show_type, NULL, 0);
 static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, ntc_show_temp, NULL, 0);
 
@@ -618,6 +641,7 @@ static int ntc_thermistor_probe(struct platform_device *pdev)
        pdev_id = of_id ? of_id->data : platform_get_device_id(pdev);
 
        data->pdata = pdata;
+       data_ntc = data;
 
        switch (pdev_id->driver_data) {
        case TYPE_NCPXXWB473:
index b78fcfeb8e13a56f652feddd27c324f377ed303b..5d5920ea94071ce88508c11f6b04444989b25355 100755 (executable)
@@ -321,35 +321,6 @@ static void s2mu106_alert_init(struct s2mu106_fuelgauge_data *fuelgauge)
        s2mu106_write_reg(fuelgauge->i2c, S2MU106_REG_IRQ_LVL, data);
 }
 
-static int s2mu106_get_batt_temperature(void){
-        struct file *fp;
-        mm_segment_t old_fs;
-        char buf[20] = {0};
-        loff_t pos = 0;
-        long int val = 0;
-
-        fp = filp_open(BATT_THERMAL_PATH, O_RDONLY, 0);
-        if (IS_ERR(fp)) {
-                pr_err("%s: file open failed\n", __func__);
-                return -EINVAL;
-        }
-
-        old_fs = get_fs();
-        set_fs(KERNEL_DS);
-        vfs_read(fp, buf, sizeof(buf), &pos);
-        if (kstrtol(buf, 10, &val) < 0) {
-                return -EINVAL;
-        }
-        set_fs(old_fs);
-        filp_close(fp, NULL);
-        val = val/100;
-        if (val == BATT_NTC100K_ORIGINAL_TEMP) {
-                val = BATT_NTC100K_NOW_TEMP;
-        }
-
-        return val;
-}
-
 static int s2mu106_set_temperature(struct s2mu106_fuelgauge_data *fuelgauge,
                        int temperature)
 {
index de9fe9a04bab7491c902fcb711abeada9e91036a..de4a30aafef7c850f9b572daf02653dc662c2672 100755 (executable)
@@ -61,4 +61,8 @@ struct ntc_thermistor_platform_data {
        int (*read_ohm)(void);
 };
 
+#define BATT_NTC100K_ORIGINAL_TEMP             1250
+#define BATT_NTC100K_NOW_TEMP                  250
+extern int ntc_show_batt_temp(void);
+
 #endif /* _LINUX_NTC_H */
old mode 100644 (file)
new mode 100755 (executable)
index ea481b3..c8f8846
 
 #define S2MU106_REG_VM                 0x67
 
-#define BATT_THERMAL_PATH              "/sys/class/hwmon/hwmon1/temp1_input"
-#define BATT_NTC100K_ORIGINAL_TEMP             1250
-#define BATT_NTC100K_NOW_TEMP                  250
-
 enum {
        CURRENT_MODE = 0,
        LOW_SOC_VOLTAGE_MODE, // not used