Skip to content

Commit d09aac0

Browse files
committed
firmware: arm_scmi: Add asynchronous sensor read if it supports
SENSOR_DESCRIPTION_GET provides attributes to indicate if the sensor supports asynchronous read. We can read that flag and use asynchronous reads for any sensors with that attribute set. Let's use the new scmi_do_xfer_with_response to support asynchronous sensor reads. Signed-off-by: Sudeep Holla <[email protected]>
1 parent 6a55331 commit d09aac0

File tree

2 files changed

+24
-8
lines changed

2 files changed

+24
-8
lines changed

drivers/firmware/arm_scmi/sensors.c

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,10 @@ static int scmi_sensor_description_get(const struct scmi_handle *handle,
136136
}
137137

138138
for (cnt = 0; cnt < num_returned; cnt++) {
139-
u32 attrh;
139+
u32 attrh, attrl;
140140
struct scmi_sensor_info *s;
141141

142+
attrl = le32_to_cpu(buf->desc[cnt].attributes_low);
142143
attrh = le32_to_cpu(buf->desc[cnt].attributes_high);
143144
s = &si->sensors[desc_index + cnt];
144145
s->id = le32_to_cpu(buf->desc[cnt].id);
@@ -147,6 +148,8 @@ static int scmi_sensor_description_get(const struct scmi_handle *handle,
147148
/* Sign extend to a full s8 */
148149
if (s->scale & SENSOR_SCALE_SIGN)
149150
s->scale |= SENSOR_SCALE_EXTEND;
151+
s->async = SUPPORTS_ASYNC_READ(attrl);
152+
s->num_trip_points = NUM_TRIP_POINTS(attrl);
150153
strlcpy(s->name, buf->desc[cnt].name, SCMI_MAX_STR_SIZE);
151154
}
152155

@@ -214,25 +217,36 @@ static int scmi_sensor_reading_get(const struct scmi_handle *handle,
214217
u32 sensor_id, u64 *value)
215218
{
216219
int ret;
220+
__le32 *pval;
217221
struct scmi_xfer *t;
218222
struct scmi_msg_sensor_reading_get *sensor;
223+
struct sensors_info *si = handle->sensor_priv;
224+
struct scmi_sensor_info *s = si->sensors + sensor_id;
219225

220226
ret = scmi_xfer_get_init(handle, SENSOR_READING_GET,
221227
SCMI_PROTOCOL_SENSOR, sizeof(*sensor),
222228
sizeof(u64), &t);
223229
if (ret)
224230
return ret;
225231

232+
pval = t->rx.buf;
226233
sensor = t->tx.buf;
227234
sensor->id = cpu_to_le32(sensor_id);
228-
sensor->flags = cpu_to_le32(0);
229-
230-
ret = scmi_do_xfer(handle, t);
231-
if (!ret) {
232-
__le32 *pval = t->rx.buf;
233235

234-
*value = le32_to_cpu(*pval);
235-
*value |= (u64)le32_to_cpu(*(pval + 1)) << 32;
236+
if (s->async) {
237+
sensor->flags = cpu_to_le32(SENSOR_READ_ASYNC);
238+
ret = scmi_do_xfer_with_response(handle, t);
239+
if (!ret) {
240+
*value = le32_to_cpu(*(pval + 1));
241+
*value |= (u64)le32_to_cpu(*(pval + 2)) << 32;
242+
}
243+
} else {
244+
sensor->flags = cpu_to_le32(0);
245+
ret = scmi_do_xfer(handle, t);
246+
if (!ret) {
247+
*value = le32_to_cpu(*pval);
248+
*value |= (u64)le32_to_cpu(*(pval + 1)) << 32;
249+
}
236250
}
237251

238252
scmi_xfer_put(handle, t);

include/linux/scmi_protocol.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,8 @@ struct scmi_sensor_info {
145145
u32 id;
146146
u8 type;
147147
s8 scale;
148+
u8 num_trip_points;
149+
bool async;
148150
char name[SCMI_MAX_STR_SIZE];
149151
};
150152

0 commit comments

Comments
 (0)