diff options
Diffstat (limited to 'drivers/firmware/arm_scmi/sensors.c')
| -rw-r--r-- | drivers/firmware/arm_scmi/sensors.c | 57 | 
1 files changed, 34 insertions, 23 deletions
diff --git a/drivers/firmware/arm_scmi/sensors.c b/drivers/firmware/arm_scmi/sensors.c index 0e94ab56f679..a400ea805fc2 100644 --- a/drivers/firmware/arm_scmi/sensors.c +++ b/drivers/firmware/arm_scmi/sensors.c @@ -9,8 +9,8 @@  enum scmi_sensor_protocol_cmd {  	SENSOR_DESCRIPTION_GET = 0x3, -	SENSOR_CONFIG_SET = 0x4, -	SENSOR_TRIP_POINT_SET = 0x5, +	SENSOR_TRIP_POINT_NOTIFY = 0x4, +	SENSOR_TRIP_POINT_CONFIG = 0x5,  	SENSOR_READING_GET = 0x6,  }; @@ -42,9 +42,10 @@ struct scmi_msg_resp_sensor_description {  	} desc[0];  }; -struct scmi_msg_set_sensor_config { +struct scmi_msg_sensor_trip_point_notify {  	__le32 id;  	__le32 event_control; +#define SENSOR_TP_NOTIFY_ALL	BIT(0)  };  struct scmi_msg_set_sensor_trip_point { @@ -119,7 +120,7 @@ static int scmi_sensor_description_get(const struct scmi_handle *handle,  	do {  		/* Set the number of sensors to be skipped/already read */ -		*(__le32 *)t->tx.buf = cpu_to_le32(desc_index); +		put_unaligned_le32(desc_index, t->tx.buf);  		ret = scmi_do_xfer(handle, t);  		if (ret) @@ -135,9 +136,10 @@ static int scmi_sensor_description_get(const struct scmi_handle *handle,  		}  		for (cnt = 0; cnt < num_returned; cnt++) { -			u32 attrh; +			u32 attrh, attrl;  			struct scmi_sensor_info *s; +			attrl = le32_to_cpu(buf->desc[cnt].attributes_low);  			attrh = le32_to_cpu(buf->desc[cnt].attributes_high);  			s = &si->sensors[desc_index + cnt];  			s->id = le32_to_cpu(buf->desc[cnt].id); @@ -146,6 +148,8 @@ static int scmi_sensor_description_get(const struct scmi_handle *handle,  			/* Sign extend to a full s8 */  			if (s->scale & SENSOR_SCALE_SIGN)  				s->scale |= SENSOR_SCALE_EXTEND; +			s->async = SUPPORTS_ASYNC_READ(attrl); +			s->num_trip_points = NUM_TRIP_POINTS(attrl);  			strlcpy(s->name, buf->desc[cnt].name, SCMI_MAX_STR_SIZE);  		} @@ -160,15 +164,15 @@ static int scmi_sensor_description_get(const struct scmi_handle *handle,  	return ret;  } -static int -scmi_sensor_configuration_set(const struct scmi_handle *handle, u32 sensor_id) +static int scmi_sensor_trip_point_notify(const struct scmi_handle *handle, +					 u32 sensor_id, bool enable)  {  	int ret; -	u32 evt_cntl = BIT(0); +	u32 evt_cntl = enable ? SENSOR_TP_NOTIFY_ALL : 0;  	struct scmi_xfer *t; -	struct scmi_msg_set_sensor_config *cfg; +	struct scmi_msg_sensor_trip_point_notify *cfg; -	ret = scmi_xfer_get_init(handle, SENSOR_CONFIG_SET, +	ret = scmi_xfer_get_init(handle, SENSOR_TRIP_POINT_NOTIFY,  				 SCMI_PROTOCOL_SENSOR, sizeof(*cfg), 0, &t);  	if (ret)  		return ret; @@ -183,15 +187,16 @@ scmi_sensor_configuration_set(const struct scmi_handle *handle, u32 sensor_id)  	return ret;  } -static int scmi_sensor_trip_point_set(const struct scmi_handle *handle, -				      u32 sensor_id, u8 trip_id, u64 trip_value) +static int +scmi_sensor_trip_point_config(const struct scmi_handle *handle, u32 sensor_id, +			      u8 trip_id, u64 trip_value)  {  	int ret;  	u32 evt_cntl = SENSOR_TP_BOTH;  	struct scmi_xfer *t;  	struct scmi_msg_set_sensor_trip_point *trip; -	ret = scmi_xfer_get_init(handle, SENSOR_TRIP_POINT_SET, +	ret = scmi_xfer_get_init(handle, SENSOR_TRIP_POINT_CONFIG,  				 SCMI_PROTOCOL_SENSOR, sizeof(*trip), 0, &t);  	if (ret)  		return ret; @@ -209,11 +214,13 @@ static int scmi_sensor_trip_point_set(const struct scmi_handle *handle,  }  static int scmi_sensor_reading_get(const struct scmi_handle *handle, -				   u32 sensor_id, bool async, u64 *value) +				   u32 sensor_id, u64 *value)  {  	int ret;  	struct scmi_xfer *t;  	struct scmi_msg_sensor_reading_get *sensor; +	struct sensors_info *si = handle->sensor_priv; +	struct scmi_sensor_info *s = si->sensors + sensor_id;  	ret = scmi_xfer_get_init(handle, SENSOR_READING_GET,  				 SCMI_PROTOCOL_SENSOR, sizeof(*sensor), @@ -223,14 +230,18 @@ static int scmi_sensor_reading_get(const struct scmi_handle *handle,  	sensor = t->tx.buf;  	sensor->id = cpu_to_le32(sensor_id); -	sensor->flags = cpu_to_le32(async ? SENSOR_READ_ASYNC : 0); -	ret = scmi_do_xfer(handle, t); -	if (!ret) { -		__le32 *pval = t->rx.buf; - -		*value = le32_to_cpu(*pval); -		*value |= (u64)le32_to_cpu(*(pval + 1)) << 32; +	if (s->async) { +		sensor->flags = cpu_to_le32(SENSOR_READ_ASYNC); +		ret = scmi_do_xfer_with_response(handle, t); +		if (!ret) +			*value = get_unaligned_le64((void *) +						    ((__le32 *)t->rx.buf + 1)); +	} else { +		sensor->flags = cpu_to_le32(0); +		ret = scmi_do_xfer(handle, t); +		if (!ret) +			*value = get_unaligned_le64(t->rx.buf);  	}  	scmi_xfer_put(handle, t); @@ -255,8 +266,8 @@ static int scmi_sensor_count_get(const struct scmi_handle *handle)  static struct scmi_sensor_ops sensor_ops = {  	.count_get = scmi_sensor_count_get,  	.info_get = scmi_sensor_info_get, -	.configuration_set = scmi_sensor_configuration_set, -	.trip_point_set = scmi_sensor_trip_point_set, +	.trip_point_notify = scmi_sensor_trip_point_notify, +	.trip_point_config = scmi_sensor_trip_point_config,  	.reading_get = scmi_sensor_reading_get,  };  |