Commit 8b71bce4 authored by Amit Kucheria's avatar Amit Kucheria Committed by Daniel Lezcano

drivers: thermal: tsens: Get rid of id field in tsens_sensor

There are two fields - id and hw_id - to track what sensor an action was
to performed on. This was because the sensors connected to a TSENS IP
might not be contiguous i.e. 1, 2, 4, 5 with 3 being skipped.

This causes confusion in the code which uses hw_id sometimes and id
other times (tsens_get_temp, tsens_get_trend).

Switch to only using the hw_id field to track the physical ID of the
sensor. When we iterate through all the sensors connected to an IP
block, we use an index i to loop through the list of sensors, and then
return the actual hw_id that is registered on that index.
Signed-off-by: default avatarAmit Kucheria <amit.kucheria@linaro.org>
Reviewed-by: default avatarStephen Boyd <swboyd@chromium.org>
Reviewed-by: default avatarDaniel Lezcano <daniel.lezcano@linaro.org>
Signed-off-by: default avatarDaniel Lezcano <daniel.lezcano@linaro.org>
Link: https://lore.kernel.org/r/30206cd47d303d2dcaef87f4e3c7173481a0bddd.1572526427.git.amit.kucheria@linaro.org
parent 9809797b
...@@ -245,11 +245,11 @@ static inline int code_to_mdegC(u32 adc_code, const struct tsens_sensor *s) ...@@ -245,11 +245,11 @@ static inline int code_to_mdegC(u32 adc_code, const struct tsens_sensor *s)
return adc_code * slope + offset; return adc_code * slope + offset;
} }
static int get_temp_8960(struct tsens_priv *priv, int id, int *temp) static int get_temp_8960(struct tsens_sensor *s, int *temp)
{ {
int ret; int ret;
u32 code, trdy; u32 code, trdy;
const struct tsens_sensor *s = &priv->sensor[id]; struct tsens_priv *priv = s->priv;
unsigned long timeout; unsigned long timeout;
timeout = jiffies + usecs_to_jiffies(TIMEOUT_US); timeout = jiffies + usecs_to_jiffies(TIMEOUT_US);
......
...@@ -83,11 +83,12 @@ static inline int code_to_degc(u32 adc_code, const struct tsens_sensor *s) ...@@ -83,11 +83,12 @@ static inline int code_to_degc(u32 adc_code, const struct tsens_sensor *s)
return degc; return degc;
} }
int get_temp_tsens_valid(struct tsens_priv *priv, int i, int *temp) int get_temp_tsens_valid(struct tsens_sensor *s, int *temp)
{ {
struct tsens_sensor *s = &priv->sensor[i]; struct tsens_priv *priv = s->priv;
u32 temp_idx = LAST_TEMP_0 + s->hw_id; int hw_id = s->hw_id;
u32 valid_idx = VALID_0 + s->hw_id; u32 temp_idx = LAST_TEMP_0 + hw_id;
u32 valid_idx = VALID_0 + hw_id;
u32 last_temp = 0, valid, mask; u32 last_temp = 0, valid, mask;
int ret; int ret;
...@@ -123,12 +124,13 @@ int get_temp_tsens_valid(struct tsens_priv *priv, int i, int *temp) ...@@ -123,12 +124,13 @@ int get_temp_tsens_valid(struct tsens_priv *priv, int i, int *temp)
return 0; return 0;
} }
int get_temp_common(struct tsens_priv *priv, int i, int *temp) int get_temp_common(struct tsens_sensor *s, int *temp)
{ {
struct tsens_sensor *s = &priv->sensor[i]; struct tsens_priv *priv = s->priv;
int hw_id = s->hw_id;
int last_temp = 0, ret; int last_temp = 0, ret;
ret = regmap_field_read(priv->rf[LAST_TEMP_0 + s->hw_id], &last_temp); ret = regmap_field_read(priv->rf[LAST_TEMP_0 + hw_id], &last_temp);
if (ret) if (ret)
return ret; return ret;
......
...@@ -14,19 +14,19 @@ ...@@ -14,19 +14,19 @@
static int tsens_get_temp(void *data, int *temp) static int tsens_get_temp(void *data, int *temp)
{ {
const struct tsens_sensor *s = data; struct tsens_sensor *s = data;
struct tsens_priv *priv = s->priv; struct tsens_priv *priv = s->priv;
return priv->ops->get_temp(priv, s->id, temp); return priv->ops->get_temp(s, temp);
} }
static int tsens_get_trend(void *data, int trip, enum thermal_trend *trend) static int tsens_get_trend(void *data, int trip, enum thermal_trend *trend)
{ {
const struct tsens_sensor *s = data; struct tsens_sensor *s = data;
struct tsens_priv *priv = s->priv; struct tsens_priv *priv = s->priv;
if (priv->ops->get_trend) if (priv->ops->get_trend)
return priv->ops->get_trend(priv, s->id, trend); return priv->ops->get_trend(s, trend);
return -ENOTSUPP; return -ENOTSUPP;
} }
...@@ -86,8 +86,7 @@ static int tsens_register(struct tsens_priv *priv) ...@@ -86,8 +86,7 @@ static int tsens_register(struct tsens_priv *priv)
for (i = 0; i < priv->num_sensors; i++) { for (i = 0; i < priv->num_sensors; i++) {
priv->sensor[i].priv = priv; priv->sensor[i].priv = priv;
priv->sensor[i].id = i; tzd = devm_thermal_zone_of_sensor_register(priv->dev, priv->sensor[i].hw_id,
tzd = devm_thermal_zone_of_sensor_register(priv->dev, i,
&priv->sensor[i], &priv->sensor[i],
&tsens_of_ops); &tsens_of_ops);
if (IS_ERR(tzd)) if (IS_ERR(tzd))
......
...@@ -32,7 +32,6 @@ enum tsens_ver { ...@@ -32,7 +32,6 @@ enum tsens_ver {
* @priv: tsens device instance that this sensor is connected to * @priv: tsens device instance that this sensor is connected to
* @tzd: pointer to the thermal zone that this sensor is in * @tzd: pointer to the thermal zone that this sensor is in
* @offset: offset of temperature adjustment curve * @offset: offset of temperature adjustment curve
* @id: Sensor ID
* @hw_id: HW ID can be used in case of platform-specific IDs * @hw_id: HW ID can be used in case of platform-specific IDs
* @slope: slope of temperature adjustment curve * @slope: slope of temperature adjustment curve
* @status: 8960-specific variable to track 8960 and 8660 status register offset * @status: 8960-specific variable to track 8960 and 8660 status register offset
...@@ -41,7 +40,6 @@ struct tsens_sensor { ...@@ -41,7 +40,6 @@ struct tsens_sensor {
struct tsens_priv *priv; struct tsens_priv *priv;
struct thermal_zone_device *tzd; struct thermal_zone_device *tzd;
int offset; int offset;
unsigned int id;
unsigned int hw_id; unsigned int hw_id;
int slope; int slope;
u32 status; u32 status;
...@@ -62,13 +60,13 @@ struct tsens_ops { ...@@ -62,13 +60,13 @@ struct tsens_ops {
/* mandatory callbacks */ /* mandatory callbacks */
int (*init)(struct tsens_priv *priv); int (*init)(struct tsens_priv *priv);
int (*calibrate)(struct tsens_priv *priv); int (*calibrate)(struct tsens_priv *priv);
int (*get_temp)(struct tsens_priv *priv, int i, int *temp); int (*get_temp)(struct tsens_sensor *s, int *temp);
/* optional callbacks */ /* optional callbacks */
int (*enable)(struct tsens_priv *priv, int i); int (*enable)(struct tsens_priv *priv, int i);
void (*disable)(struct tsens_priv *priv); void (*disable)(struct tsens_priv *priv);
int (*suspend)(struct tsens_priv *priv); int (*suspend)(struct tsens_priv *priv);
int (*resume)(struct tsens_priv *priv); int (*resume)(struct tsens_priv *priv);
int (*get_trend)(struct tsens_priv *priv, int i, enum thermal_trend *trend); int (*get_trend)(struct tsens_sensor *s, enum thermal_trend *trend);
}; };
#define REG_FIELD_FOR_EACH_SENSOR11(_name, _offset, _startbit, _stopbit) \ #define REG_FIELD_FOR_EACH_SENSOR11(_name, _offset, _startbit, _stopbit) \
...@@ -314,8 +312,8 @@ struct tsens_priv { ...@@ -314,8 +312,8 @@ struct tsens_priv {
char *qfprom_read(struct device *dev, const char *cname); char *qfprom_read(struct device *dev, const char *cname);
void compute_intercept_slope(struct tsens_priv *priv, u32 *pt1, u32 *pt2, u32 mode); void compute_intercept_slope(struct tsens_priv *priv, u32 *pt1, u32 *pt2, u32 mode);
int init_common(struct tsens_priv *priv); int init_common(struct tsens_priv *priv);
int get_temp_tsens_valid(struct tsens_priv *priv, int i, int *temp); int get_temp_tsens_valid(struct tsens_sensor *s, int *temp);
int get_temp_common(struct tsens_priv *priv, int i, int *temp); int get_temp_common(struct tsens_sensor *s, int *temp);
/* TSENS target */ /* TSENS target */
extern const struct tsens_plat_data data_8960; extern const struct tsens_plat_data data_8960;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment