Skip to content

Commit

Permalink
drivers: thermal: tsens: Add new operation to check if a sensor is en…
Browse files Browse the repository at this point in the history
…abled

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>
  • Loading branch information
Amit Kucheria authored and Eduardo Valentin committed May 14, 2019
1 parent fc7d18c commit 3e6a8fb
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 0 deletions.
14 changes: 14 additions & 0 deletions drivers/thermal/qcom/tsens-common.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions drivers/thermal/qcom/tsens-v0_1.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
1 change: 1 addition & 0 deletions drivers/thermal/qcom/tsens-v2.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
5 changes: 5 additions & 0 deletions drivers/thermal/qcom/tsens.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions drivers/thermal/qcom/tsens.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 3e6a8fb

Please sign in to comment.