]> www.infradead.org Git - linux-platform-drivers-x86.git/commitdiff
drivers: thermal: tsens: Add new operation to check if a sensor is enabled
authorAmit Kucheria <amit.kucheria@linaro.org>
Wed, 20 Mar 2019 13:17:53 +0000 (18:47 +0530)
committerEduardo Valentin <edubezval@gmail.com>
Tue, 14 May 2019 13:59:17 +0000 (06:59 -0700)
is_sensor_enabled() checks if the sensors are enabled on this platform.
It is possible that the SoC might choose not to enable all the sensors
that the IP block is capable of supporting.

Signed-off-by: Amit Kucheria <amit.kucheria@linaro.org>
Signed-off-by: Eduardo Valentin <edubezval@gmail.com>
drivers/thermal/qcom/tsens-common.c
drivers/thermal/qcom/tsens-v0_1.c
drivers/thermal/qcom/tsens-v2.c
drivers/thermal/qcom/tsens.c
drivers/thermal/qcom/tsens.h

index 9d7a6c328ae0a44028b9ebb47112c39ce5fd1f5e..c76f8cfb25a2a3d8f346cf391ca29d993eb69104 100644 (file)
@@ -69,6 +69,20 @@ void compute_intercept_slope(struct tsens_priv *priv, u32 *p1,
        }
 }
 
+bool is_sensor_enabled(struct tsens_priv *priv, u32 hw_id)
+{
+       u32 val;
+       int ret;
+
+       if ((hw_id > (priv->num_sensors - 1)) || (hw_id < 0))
+               return -EINVAL;
+       ret = regmap_field_read(priv->rf[SENSOR_EN], &val);
+       if (ret)
+               return ret;
+
+       return val & (1 << hw_id);
+}
+
 static inline int code_to_degc(u32 adc_code, const struct tsens_sensor *s)
 {
        int degc, num, den;
index a7560e9a7c10e0146344d524ce6c0f85d8f80a21..c0476bfdc0d51b45d6ef9ceb8af4a6932433d848 100644 (file)
@@ -333,6 +333,7 @@ static const struct reg_field tsens_v0_1_regfields[MAX_REGFIELDS] = {
        /* CTRL_OFFSET */
        [TSENS_EN]     = REG_FIELD(SROT_CTRL_OFF, 0,  0),
        [TSENS_SW_RST] = REG_FIELD(SROT_CTRL_OFF, 1,  1),
+       [SENSOR_EN]    = REG_FIELD(SROT_CTRL_OFF, 3, 13),
 
        /* ----- TM ------ */
        /* INTERRUPT ENABLE */
index b58f5af2fea79818a51d540e702b243ab87a7a60..788d5886cd1c43f10421872ca59b091b4cf4a091 100644 (file)
@@ -99,6 +99,7 @@ static const struct reg_field tsens_v2_regfields[MAX_REGFIELDS] = {
        /* CTRL_OFF */
        [TSENS_EN]     = REG_FIELD(SROT_CTRL_OFF,    0,  0),
        [TSENS_SW_RST] = REG_FIELD(SROT_CTRL_OFF,    1,  1),
+       [SENSOR_EN]    = REG_FIELD(SROT_CTRL_OFF,    3, 18),
 
        /* ----- TM ------ */
        /* INTERRUPT ENABLE */
index 057b33353ba34100d88ce963d041237779e153f9..fc44cac31fa582a18fce23ca9824fc206f6a3c09 100644 (file)
@@ -82,6 +82,11 @@ static int tsens_register(struct tsens_priv *priv)
        struct thermal_zone_device *tzd;
 
        for (i = 0;  i < priv->num_sensors; i++) {
+               if (!is_sensor_enabled(priv, priv->sensor[i].hw_id)) {
+                       dev_err(priv->dev, "sensor %d: disabled\n",
+                               priv->sensor[i].hw_id);
+                       continue;
+               }
                priv->sensor[i].priv = priv;
                priv->sensor[i].id = i;
                tzd = devm_thermal_zone_of_sensor_register(priv->dev, i,
index a9390e06b4dd5e6bb7eac0571815fc40b06904a5..a3bf7de88ae819b1482edb180b7b64c0f283a48a 100644 (file)
@@ -307,6 +307,7 @@ char *qfprom_read(struct device *dev, const char *cname);
 void compute_intercept_slope(struct tsens_priv *priv, u32 *pt1, u32 *pt2, u32 mode);
 int init_common(struct tsens_priv *priv);
 int get_temp_common(struct tsens_priv *priv, int i, int *temp);
+bool is_sensor_enabled(struct tsens_priv *priv, u32 hw_id);
 
 /* TSENS target */
 extern const struct tsens_plat_data data_8960;