All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] iio: cros_ec: do an early exit if not physical_device case
@ 2020-11-23 14:40 Alexandru Ardelean
  2020-11-23 14:40 ` [PATCH 2/2] iio: cros_ec: un-indent block that configures motion sensor fifo Alexandru Ardelean
  2021-02-21 16:29 ` [PATCH 1/2] iio: cros_ec: do an early exit if not physical_device case Jonathan Cameron
  0 siblings, 2 replies; 6+ messages in thread
From: Alexandru Ardelean @ 2020-11-23 14:40 UTC (permalink / raw)
  To: linux-kernel, linux-iio
  Cc: jic23, bleung, enric.balletbo, groeck, gwendal, Alexandru Ardelean

This whole code-block was put under one big if() condition/block.
This change does an early return if the 'physical_device' boolean is false,
thus unindenting the block by one level.

No other functional change has been done.

Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com>
---
 .../cros_ec_sensors/cros_ec_sensors_core.c    | 161 +++++++++---------
 1 file changed, 81 insertions(+), 80 deletions(-)

diff --git a/drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c b/drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c
index 5c6c4e6fec9b..9470014936f2 100644
--- a/drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c
+++ b/drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c
@@ -287,89 +287,90 @@ int cros_ec_sensors_core_init(struct platform_device *pdev,
 
 	indio_dev->name = pdev->name;
 
-	if (physical_device) {
-		state->param.cmd = MOTIONSENSE_CMD_INFO;
-		state->param.info.sensor_num = sensor_platform->sensor_num;
-		ret = cros_ec_motion_send_host_cmd(state, 0);
-		if (ret) {
-			dev_warn(dev, "Can not access sensor info\n");
+	if (!physical_device)
+		return 0;
+
+	state->param.cmd = MOTIONSENSE_CMD_INFO;
+	state->param.info.sensor_num = sensor_platform->sensor_num;
+	ret = cros_ec_motion_send_host_cmd(state, 0);
+	if (ret) {
+		dev_warn(dev, "Can not access sensor info\n");
+		return ret;
+	}
+	state->type = state->resp->info.type;
+	state->loc = state->resp->info.location;
+
+	/* Set sign vector, only used for backward compatibility. */
+	memset(state->sign, 1, CROS_EC_SENSOR_MAX_AXIS);
+
+	for (i = CROS_EC_SENSOR_X; i < CROS_EC_SENSOR_MAX_AXIS; i++)
+		state->calib[i].scale = MOTION_SENSE_DEFAULT_SCALE;
+
+	/* 0 is a correct value used to stop the device */
+	if (state->msg->version < 3) {
+		get_default_min_max_freq(state->resp->info.type,
+					 &frequencies[1],
+					 &frequencies[2],
+					 &state->fifo_max_event_count);
+	} else {
+		frequencies[1] = state->resp->info_3.min_frequency;
+		frequencies[2] = state->resp->info_3.max_frequency;
+		state->fifo_max_event_count =
+		    state->resp->info_3.fifo_max_event_count;
+	}
+	for (i = 0; i < ARRAY_SIZE(frequencies); i++) {
+		state->frequencies[2 * i] = frequencies[i] / 1000;
+		state->frequencies[2 * i + 1] =
+			(frequencies[i] % 1000) * 1000;
+	}
+
+	if (cros_ec_check_features(ec, EC_FEATURE_MOTION_SENSE_FIFO)) {
+		/*
+		 * Create a software buffer, feed by the EC FIFO.
+		 * We can not use trigger here, as events are generated
+		 * as soon as sample_frequency is set.
+		 */
+		struct iio_buffer *buffer;
+
+		buffer = devm_iio_kfifo_allocate(dev);
+		if (!buffer)
+			return -ENOMEM;
+
+		iio_device_attach_buffer(indio_dev, buffer);
+		indio_dev->modes = INDIO_BUFFER_SOFTWARE;
+
+		ret = cros_ec_sensorhub_register_push_data(
+				sensor_hub, sensor_platform->sensor_num,
+				indio_dev, push_data);
+		if (ret)
 			return ret;
-		}
-		state->type = state->resp->info.type;
-		state->loc = state->resp->info.location;
 
-		/* Set sign vector, only used for backward compatibility. */
-		memset(state->sign, 1, CROS_EC_SENSOR_MAX_AXIS);
+		ret = devm_add_action_or_reset(
+				dev, cros_ec_sensors_core_clean, pdev);
+		if (ret)
+			return ret;
 
-		for (i = CROS_EC_SENSOR_X; i < CROS_EC_SENSOR_MAX_AXIS; i++)
-			state->calib[i].scale = MOTION_SENSE_DEFAULT_SCALE;
-
-		/* 0 is a correct value used to stop the device */
-		if (state->msg->version < 3) {
-			get_default_min_max_freq(state->resp->info.type,
-						 &frequencies[1],
-						 &frequencies[2],
-						 &state->fifo_max_event_count);
-		} else {
-			frequencies[1] = state->resp->info_3.min_frequency;
-			frequencies[2] = state->resp->info_3.max_frequency;
-			state->fifo_max_event_count =
-			    state->resp->info_3.fifo_max_event_count;
-		}
-		for (i = 0; i < ARRAY_SIZE(frequencies); i++) {
-			state->frequencies[2 * i] = frequencies[i] / 1000;
-			state->frequencies[2 * i + 1] =
-				(frequencies[i] % 1000) * 1000;
-		}
-
-		if (cros_ec_check_features(ec, EC_FEATURE_MOTION_SENSE_FIFO)) {
-			/*
-			 * Create a software buffer, feed by the EC FIFO.
-			 * We can not use trigger here, as events are generated
-			 * as soon as sample_frequency is set.
-			 */
-			struct iio_buffer *buffer;
-
-			buffer = devm_iio_kfifo_allocate(dev);
-			if (!buffer)
-				return -ENOMEM;
-
-			iio_device_attach_buffer(indio_dev, buffer);
-			indio_dev->modes = INDIO_BUFFER_SOFTWARE;
-
-			ret = cros_ec_sensorhub_register_push_data(
-					sensor_hub, sensor_platform->sensor_num,
-					indio_dev, push_data);
-			if (ret)
-				return ret;
-
-			ret = devm_add_action_or_reset(
-					dev, cros_ec_sensors_core_clean, pdev);
-			if (ret)
-				return ret;
-
-			/* Timestamp coming from FIFO are in ns since boot. */
-			ret = iio_device_set_clock(indio_dev, CLOCK_BOOTTIME);
-			if (ret)
-				return ret;
-		} else {
-			const struct attribute **fifo_attrs;
-
-			if (has_hw_fifo)
-				fifo_attrs = cros_ec_sensor_fifo_attributes;
-			else
-				fifo_attrs = NULL;
-
-			/*
-			 * The only way to get samples in buffer is to set a
-			 * software trigger (systrig, hrtimer).
-			 */
-			ret = devm_iio_triggered_buffer_setup_ext(
-					dev, indio_dev, NULL, trigger_capture,
-					NULL, fifo_attrs);
-			if (ret)
-				return ret;
-		}
+		/* Timestamp coming from FIFO are in ns since boot. */
+		ret = iio_device_set_clock(indio_dev, CLOCK_BOOTTIME);
+		if (ret)
+			return ret;
+	} else {
+		const struct attribute **fifo_attrs;
+
+		if (has_hw_fifo)
+			fifo_attrs = cros_ec_sensor_fifo_attributes;
+		else
+			fifo_attrs = NULL;
+
+		/*
+		 * The only way to get samples in buffer is to set a
+		 * software trigger (systrig, hrtimer).
+		 */
+		ret = devm_iio_triggered_buffer_setup_ext(
+				dev, indio_dev, NULL, trigger_capture,
+				NULL, fifo_attrs);
+		if (ret)
+			return ret;
 	}
 
 	return 0;
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 2/2] iio: cros_ec: un-indent block that configures motion sensor fifo
  2020-11-23 14:40 [PATCH 1/2] iio: cros_ec: do an early exit if not physical_device case Alexandru Ardelean
@ 2020-11-23 14:40 ` Alexandru Ardelean
  2021-02-21 16:29 ` [PATCH 1/2] iio: cros_ec: do an early exit if not physical_device case Jonathan Cameron
  1 sibling, 0 replies; 6+ messages in thread
From: Alexandru Ardelean @ 2020-11-23 14:40 UTC (permalink / raw)
  To: linux-kernel, linux-iio
  Cc: jic23, bleung, enric.balletbo, groeck, gwendal, Alexandru Ardelean

This change also reverses the condition of the FIFO setup. If the feature
setup does not include a EC_FEATURE_MOTION_SENSE_FIFO flag, then the
IIO triggered buffer setup is done and first and early exit is performed.
It'a done like this because the code block (for the IIO triggered buffer
setup) is smaller.

The code block for the EC_FEATURE_MOTION_SENSE_FIFO flag has been
un-indented.

Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com>
---
 .../cros_ec_sensors/cros_ec_sensors_core.c    | 63 +++++++++----------
 1 file changed, 28 insertions(+), 35 deletions(-)

diff --git a/drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c b/drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c
index 9470014936f2..921eccd4f6a6 100644
--- a/drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c
+++ b/drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c
@@ -258,6 +258,7 @@ int cros_ec_sensors_core_init(struct platform_device *pdev,
 	struct cros_ec_sensor_platform *sensor_platform = dev_get_platdata(dev);
 	u32 ver_mask;
 	int frequencies[ARRAY_SIZE(state->frequencies) / 2] = { 0 };
+	struct iio_buffer *buffer;
 	int ret, i;
 
 	platform_set_drvdata(pdev, indio_dev);
@@ -324,37 +325,7 @@ int cros_ec_sensors_core_init(struct platform_device *pdev,
 			(frequencies[i] % 1000) * 1000;
 	}
 
-	if (cros_ec_check_features(ec, EC_FEATURE_MOTION_SENSE_FIFO)) {
-		/*
-		 * Create a software buffer, feed by the EC FIFO.
-		 * We can not use trigger here, as events are generated
-		 * as soon as sample_frequency is set.
-		 */
-		struct iio_buffer *buffer;
-
-		buffer = devm_iio_kfifo_allocate(dev);
-		if (!buffer)
-			return -ENOMEM;
-
-		iio_device_attach_buffer(indio_dev, buffer);
-		indio_dev->modes = INDIO_BUFFER_SOFTWARE;
-
-		ret = cros_ec_sensorhub_register_push_data(
-				sensor_hub, sensor_platform->sensor_num,
-				indio_dev, push_data);
-		if (ret)
-			return ret;
-
-		ret = devm_add_action_or_reset(
-				dev, cros_ec_sensors_core_clean, pdev);
-		if (ret)
-			return ret;
-
-		/* Timestamp coming from FIFO are in ns since boot. */
-		ret = iio_device_set_clock(indio_dev, CLOCK_BOOTTIME);
-		if (ret)
-			return ret;
-	} else {
+	if (!cros_ec_check_features(ec, EC_FEATURE_MOTION_SENSE_FIFO)) {
 		const struct attribute **fifo_attrs;
 
 		if (has_hw_fifo)
@@ -366,14 +337,36 @@ int cros_ec_sensors_core_init(struct platform_device *pdev,
 		 * The only way to get samples in buffer is to set a
 		 * software trigger (systrig, hrtimer).
 		 */
-		ret = devm_iio_triggered_buffer_setup_ext(
+		return devm_iio_triggered_buffer_setup_ext(
 				dev, indio_dev, NULL, trigger_capture,
 				NULL, fifo_attrs);
-		if (ret)
-			return ret;
 	}
 
-	return 0;
+	/*
+	 * Create a software buffer, feed by the EC FIFO.
+	 * We can not use trigger here, as events are generated
+	 * as soon as sample_frequency is set.
+	 */
+	buffer = devm_iio_kfifo_allocate(dev);
+	if (!buffer)
+		return -ENOMEM;
+
+	iio_device_attach_buffer(indio_dev, buffer);
+	indio_dev->modes = INDIO_BUFFER_SOFTWARE;
+
+	ret = cros_ec_sensorhub_register_push_data(
+			sensor_hub, sensor_platform->sensor_num,
+			indio_dev, push_data);
+	if (ret)
+		return ret;
+
+	ret = devm_add_action_or_reset(
+			dev, cros_ec_sensors_core_clean, pdev);
+	if (ret)
+		return ret;
+
+	/* Timestamp coming from FIFO are in ns since boot. */
+	return iio_device_set_clock(indio_dev, CLOCK_BOOTTIME);
 }
 EXPORT_SYMBOL_GPL(cros_ec_sensors_core_init);
 
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/2] iio: cros_ec: do an early exit if not physical_device case
  2020-11-23 14:40 [PATCH 1/2] iio: cros_ec: do an early exit if not physical_device case Alexandru Ardelean
  2020-11-23 14:40 ` [PATCH 2/2] iio: cros_ec: un-indent block that configures motion sensor fifo Alexandru Ardelean
@ 2021-02-21 16:29 ` Jonathan Cameron
  2021-03-02 10:46   ` Enric Balletbo i Serra
  1 sibling, 1 reply; 6+ messages in thread
From: Jonathan Cameron @ 2021-02-21 16:29 UTC (permalink / raw)
  To: Alexandru Ardelean
  Cc: linux-kernel, linux-iio, bleung, enric.balletbo, groeck, gwendal

On Mon, 23 Nov 2020 16:40:16 +0200
Alexandru Ardelean <alexandru.ardelean@analog.com> wrote:

> This whole code-block was put under one big if() condition/block.
> This change does an early return if the 'physical_device' boolean is false,
> thus unindenting the block by one level.
> 
> No other functional change has been done.
> 
> Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com>
@Gwendal, others  This series from Alex has been outstanding for a while
but may well still apply.
Ideally looking for an ack.

Thanks,

Jonathan
 
> ---
>  .../cros_ec_sensors/cros_ec_sensors_core.c    | 161 +++++++++---------
>  1 file changed, 81 insertions(+), 80 deletions(-)
> 
> diff --git a/drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c b/drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c
> index 5c6c4e6fec9b..9470014936f2 100644
> --- a/drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c
> +++ b/drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c
> @@ -287,89 +287,90 @@ int cros_ec_sensors_core_init(struct platform_device *pdev,
>  
>  	indio_dev->name = pdev->name;
>  
> -	if (physical_device) {
> -		state->param.cmd = MOTIONSENSE_CMD_INFO;
> -		state->param.info.sensor_num = sensor_platform->sensor_num;
> -		ret = cros_ec_motion_send_host_cmd(state, 0);
> -		if (ret) {
> -			dev_warn(dev, "Can not access sensor info\n");
> +	if (!physical_device)
> +		return 0;
> +
> +	state->param.cmd = MOTIONSENSE_CMD_INFO;
> +	state->param.info.sensor_num = sensor_platform->sensor_num;
> +	ret = cros_ec_motion_send_host_cmd(state, 0);
> +	if (ret) {
> +		dev_warn(dev, "Can not access sensor info\n");
> +		return ret;
> +	}
> +	state->type = state->resp->info.type;
> +	state->loc = state->resp->info.location;
> +
> +	/* Set sign vector, only used for backward compatibility. */
> +	memset(state->sign, 1, CROS_EC_SENSOR_MAX_AXIS);
> +
> +	for (i = CROS_EC_SENSOR_X; i < CROS_EC_SENSOR_MAX_AXIS; i++)
> +		state->calib[i].scale = MOTION_SENSE_DEFAULT_SCALE;
> +
> +	/* 0 is a correct value used to stop the device */
> +	if (state->msg->version < 3) {
> +		get_default_min_max_freq(state->resp->info.type,
> +					 &frequencies[1],
> +					 &frequencies[2],
> +					 &state->fifo_max_event_count);
> +	} else {
> +		frequencies[1] = state->resp->info_3.min_frequency;
> +		frequencies[2] = state->resp->info_3.max_frequency;
> +		state->fifo_max_event_count =
> +		    state->resp->info_3.fifo_max_event_count;
> +	}
> +	for (i = 0; i < ARRAY_SIZE(frequencies); i++) {
> +		state->frequencies[2 * i] = frequencies[i] / 1000;
> +		state->frequencies[2 * i + 1] =
> +			(frequencies[i] % 1000) * 1000;
> +	}
> +
> +	if (cros_ec_check_features(ec, EC_FEATURE_MOTION_SENSE_FIFO)) {
> +		/*
> +		 * Create a software buffer, feed by the EC FIFO.
> +		 * We can not use trigger here, as events are generated
> +		 * as soon as sample_frequency is set.
> +		 */
> +		struct iio_buffer *buffer;
> +
> +		buffer = devm_iio_kfifo_allocate(dev);
> +		if (!buffer)
> +			return -ENOMEM;
> +
> +		iio_device_attach_buffer(indio_dev, buffer);
> +		indio_dev->modes = INDIO_BUFFER_SOFTWARE;
> +
> +		ret = cros_ec_sensorhub_register_push_data(
> +				sensor_hub, sensor_platform->sensor_num,
> +				indio_dev, push_data);
> +		if (ret)
>  			return ret;
> -		}
> -		state->type = state->resp->info.type;
> -		state->loc = state->resp->info.location;
>  
> -		/* Set sign vector, only used for backward compatibility. */
> -		memset(state->sign, 1, CROS_EC_SENSOR_MAX_AXIS);
> +		ret = devm_add_action_or_reset(
> +				dev, cros_ec_sensors_core_clean, pdev);
> +		if (ret)
> +			return ret;
>  
> -		for (i = CROS_EC_SENSOR_X; i < CROS_EC_SENSOR_MAX_AXIS; i++)
> -			state->calib[i].scale = MOTION_SENSE_DEFAULT_SCALE;
> -
> -		/* 0 is a correct value used to stop the device */
> -		if (state->msg->version < 3) {
> -			get_default_min_max_freq(state->resp->info.type,
> -						 &frequencies[1],
> -						 &frequencies[2],
> -						 &state->fifo_max_event_count);
> -		} else {
> -			frequencies[1] = state->resp->info_3.min_frequency;
> -			frequencies[2] = state->resp->info_3.max_frequency;
> -			state->fifo_max_event_count =
> -			    state->resp->info_3.fifo_max_event_count;
> -		}
> -		for (i = 0; i < ARRAY_SIZE(frequencies); i++) {
> -			state->frequencies[2 * i] = frequencies[i] / 1000;
> -			state->frequencies[2 * i + 1] =
> -				(frequencies[i] % 1000) * 1000;
> -		}
> -
> -		if (cros_ec_check_features(ec, EC_FEATURE_MOTION_SENSE_FIFO)) {
> -			/*
> -			 * Create a software buffer, feed by the EC FIFO.
> -			 * We can not use trigger here, as events are generated
> -			 * as soon as sample_frequency is set.
> -			 */
> -			struct iio_buffer *buffer;
> -
> -			buffer = devm_iio_kfifo_allocate(dev);
> -			if (!buffer)
> -				return -ENOMEM;
> -
> -			iio_device_attach_buffer(indio_dev, buffer);
> -			indio_dev->modes = INDIO_BUFFER_SOFTWARE;
> -
> -			ret = cros_ec_sensorhub_register_push_data(
> -					sensor_hub, sensor_platform->sensor_num,
> -					indio_dev, push_data);
> -			if (ret)
> -				return ret;
> -
> -			ret = devm_add_action_or_reset(
> -					dev, cros_ec_sensors_core_clean, pdev);
> -			if (ret)
> -				return ret;
> -
> -			/* Timestamp coming from FIFO are in ns since boot. */
> -			ret = iio_device_set_clock(indio_dev, CLOCK_BOOTTIME);
> -			if (ret)
> -				return ret;
> -		} else {
> -			const struct attribute **fifo_attrs;
> -
> -			if (has_hw_fifo)
> -				fifo_attrs = cros_ec_sensor_fifo_attributes;
> -			else
> -				fifo_attrs = NULL;
> -
> -			/*
> -			 * The only way to get samples in buffer is to set a
> -			 * software trigger (systrig, hrtimer).
> -			 */
> -			ret = devm_iio_triggered_buffer_setup_ext(
> -					dev, indio_dev, NULL, trigger_capture,
> -					NULL, fifo_attrs);
> -			if (ret)
> -				return ret;
> -		}
> +		/* Timestamp coming from FIFO are in ns since boot. */
> +		ret = iio_device_set_clock(indio_dev, CLOCK_BOOTTIME);
> +		if (ret)
> +			return ret;
> +	} else {
> +		const struct attribute **fifo_attrs;
> +
> +		if (has_hw_fifo)
> +			fifo_attrs = cros_ec_sensor_fifo_attributes;
> +		else
> +			fifo_attrs = NULL;
> +
> +		/*
> +		 * The only way to get samples in buffer is to set a
> +		 * software trigger (systrig, hrtimer).
> +		 */
> +		ret = devm_iio_triggered_buffer_setup_ext(
> +				dev, indio_dev, NULL, trigger_capture,
> +				NULL, fifo_attrs);
> +		if (ret)
> +			return ret;
>  	}
>  
>  	return 0;


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/2] iio: cros_ec: do an early exit if not physical_device case
  2021-02-21 16:29 ` [PATCH 1/2] iio: cros_ec: do an early exit if not physical_device case Jonathan Cameron
@ 2021-03-02 10:46   ` Enric Balletbo i Serra
  2021-03-07 11:59     ` Jonathan Cameron
  0 siblings, 1 reply; 6+ messages in thread
From: Enric Balletbo i Serra @ 2021-03-02 10:46 UTC (permalink / raw)
  To: Jonathan Cameron, Alexandru Ardelean
  Cc: linux-kernel, linux-iio, bleung, groeck, gwendal

Hi all,

On 21/2/21 17:29, Jonathan Cameron wrote:
> On Mon, 23 Nov 2020 16:40:16 +0200
> Alexandru Ardelean <alexandru.ardelean@analog.com> wrote:
> 
>> This whole code-block was put under one big if() condition/block.
>> This change does an early return if the 'physical_device' boolean is false,
>> thus unindenting the block by one level.
>>
>> No other functional change has been done.
>>
>> Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com>
> @Gwendal, others  This series from Alex has been outstanding for a while
> but may well still apply.
> Ideally looking for an ack.
> 

This looks good to me.

Acked-by: Enric Balletbo i Serra <enric.balletbo@collabora.com>

Thanks,
 Enric

> Thanks,
> 
> Jonathan
>  
>> ---
>>  .../cros_ec_sensors/cros_ec_sensors_core.c    | 161 +++++++++---------
>>  1 file changed, 81 insertions(+), 80 deletions(-)
>>
>> diff --git a/drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c b/drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c
>> index 5c6c4e6fec9b..9470014936f2 100644
>> --- a/drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c
>> +++ b/drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c
>> @@ -287,89 +287,90 @@ int cros_ec_sensors_core_init(struct platform_device *pdev,
>>  
>>  	indio_dev->name = pdev->name;
>>  
>> -	if (physical_device) {
>> -		state->param.cmd = MOTIONSENSE_CMD_INFO;
>> -		state->param.info.sensor_num = sensor_platform->sensor_num;
>> -		ret = cros_ec_motion_send_host_cmd(state, 0);
>> -		if (ret) {
>> -			dev_warn(dev, "Can not access sensor info\n");
>> +	if (!physical_device)
>> +		return 0;
>> +
>> +	state->param.cmd = MOTIONSENSE_CMD_INFO;
>> +	state->param.info.sensor_num = sensor_platform->sensor_num;
>> +	ret = cros_ec_motion_send_host_cmd(state, 0);
>> +	if (ret) {
>> +		dev_warn(dev, "Can not access sensor info\n");
>> +		return ret;
>> +	}
>> +	state->type = state->resp->info.type;
>> +	state->loc = state->resp->info.location;
>> +
>> +	/* Set sign vector, only used for backward compatibility. */
>> +	memset(state->sign, 1, CROS_EC_SENSOR_MAX_AXIS);
>> +
>> +	for (i = CROS_EC_SENSOR_X; i < CROS_EC_SENSOR_MAX_AXIS; i++)
>> +		state->calib[i].scale = MOTION_SENSE_DEFAULT_SCALE;
>> +
>> +	/* 0 is a correct value used to stop the device */
>> +	if (state->msg->version < 3) {
>> +		get_default_min_max_freq(state->resp->info.type,
>> +					 &frequencies[1],
>> +					 &frequencies[2],
>> +					 &state->fifo_max_event_count);
>> +	} else {
>> +		frequencies[1] = state->resp->info_3.min_frequency;
>> +		frequencies[2] = state->resp->info_3.max_frequency;
>> +		state->fifo_max_event_count =
>> +		    state->resp->info_3.fifo_max_event_count;
>> +	}
>> +	for (i = 0; i < ARRAY_SIZE(frequencies); i++) {
>> +		state->frequencies[2 * i] = frequencies[i] / 1000;
>> +		state->frequencies[2 * i + 1] =
>> +			(frequencies[i] % 1000) * 1000;
>> +	}
>> +
>> +	if (cros_ec_check_features(ec, EC_FEATURE_MOTION_SENSE_FIFO)) {
>> +		/*
>> +		 * Create a software buffer, feed by the EC FIFO.
>> +		 * We can not use trigger here, as events are generated
>> +		 * as soon as sample_frequency is set.
>> +		 */
>> +		struct iio_buffer *buffer;
>> +
>> +		buffer = devm_iio_kfifo_allocate(dev);
>> +		if (!buffer)
>> +			return -ENOMEM;
>> +
>> +		iio_device_attach_buffer(indio_dev, buffer);
>> +		indio_dev->modes = INDIO_BUFFER_SOFTWARE;
>> +
>> +		ret = cros_ec_sensorhub_register_push_data(
>> +				sensor_hub, sensor_platform->sensor_num,
>> +				indio_dev, push_data);
>> +		if (ret)
>>  			return ret;
>> -		}
>> -		state->type = state->resp->info.type;
>> -		state->loc = state->resp->info.location;
>>  
>> -		/* Set sign vector, only used for backward compatibility. */
>> -		memset(state->sign, 1, CROS_EC_SENSOR_MAX_AXIS);
>> +		ret = devm_add_action_or_reset(
>> +				dev, cros_ec_sensors_core_clean, pdev);
>> +		if (ret)
>> +			return ret;
>>  
>> -		for (i = CROS_EC_SENSOR_X; i < CROS_EC_SENSOR_MAX_AXIS; i++)
>> -			state->calib[i].scale = MOTION_SENSE_DEFAULT_SCALE;
>> -
>> -		/* 0 is a correct value used to stop the device */
>> -		if (state->msg->version < 3) {
>> -			get_default_min_max_freq(state->resp->info.type,
>> -						 &frequencies[1],
>> -						 &frequencies[2],
>> -						 &state->fifo_max_event_count);
>> -		} else {
>> -			frequencies[1] = state->resp->info_3.min_frequency;
>> -			frequencies[2] = state->resp->info_3.max_frequency;
>> -			state->fifo_max_event_count =
>> -			    state->resp->info_3.fifo_max_event_count;
>> -		}
>> -		for (i = 0; i < ARRAY_SIZE(frequencies); i++) {
>> -			state->frequencies[2 * i] = frequencies[i] / 1000;
>> -			state->frequencies[2 * i + 1] =
>> -				(frequencies[i] % 1000) * 1000;
>> -		}
>> -
>> -		if (cros_ec_check_features(ec, EC_FEATURE_MOTION_SENSE_FIFO)) {
>> -			/*
>> -			 * Create a software buffer, feed by the EC FIFO.
>> -			 * We can not use trigger here, as events are generated
>> -			 * as soon as sample_frequency is set.
>> -			 */
>> -			struct iio_buffer *buffer;
>> -
>> -			buffer = devm_iio_kfifo_allocate(dev);
>> -			if (!buffer)
>> -				return -ENOMEM;
>> -
>> -			iio_device_attach_buffer(indio_dev, buffer);
>> -			indio_dev->modes = INDIO_BUFFER_SOFTWARE;
>> -
>> -			ret = cros_ec_sensorhub_register_push_data(
>> -					sensor_hub, sensor_platform->sensor_num,
>> -					indio_dev, push_data);
>> -			if (ret)
>> -				return ret;
>> -
>> -			ret = devm_add_action_or_reset(
>> -					dev, cros_ec_sensors_core_clean, pdev);
>> -			if (ret)
>> -				return ret;
>> -
>> -			/* Timestamp coming from FIFO are in ns since boot. */
>> -			ret = iio_device_set_clock(indio_dev, CLOCK_BOOTTIME);
>> -			if (ret)
>> -				return ret;
>> -		} else {
>> -			const struct attribute **fifo_attrs;
>> -
>> -			if (has_hw_fifo)
>> -				fifo_attrs = cros_ec_sensor_fifo_attributes;
>> -			else
>> -				fifo_attrs = NULL;
>> -
>> -			/*
>> -			 * The only way to get samples in buffer is to set a
>> -			 * software trigger (systrig, hrtimer).
>> -			 */
>> -			ret = devm_iio_triggered_buffer_setup_ext(
>> -					dev, indio_dev, NULL, trigger_capture,
>> -					NULL, fifo_attrs);
>> -			if (ret)
>> -				return ret;
>> -		}
>> +		/* Timestamp coming from FIFO are in ns since boot. */
>> +		ret = iio_device_set_clock(indio_dev, CLOCK_BOOTTIME);
>> +		if (ret)
>> +			return ret;
>> +	} else {
>> +		const struct attribute **fifo_attrs;
>> +
>> +		if (has_hw_fifo)
>> +			fifo_attrs = cros_ec_sensor_fifo_attributes;
>> +		else
>> +			fifo_attrs = NULL;
>> +
>> +		/*
>> +		 * The only way to get samples in buffer is to set a
>> +		 * software trigger (systrig, hrtimer).
>> +		 */
>> +		ret = devm_iio_triggered_buffer_setup_ext(
>> +				dev, indio_dev, NULL, trigger_capture,
>> +				NULL, fifo_attrs);
>> +		if (ret)
>> +			return ret;
>>  	}
>>  
>>  	return 0;
> 

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/2] iio: cros_ec: do an early exit if not physical_device case
  2021-03-02 10:46   ` Enric Balletbo i Serra
@ 2021-03-07 11:59     ` Jonathan Cameron
  2021-03-07 18:45       ` Alexandru Ardelean
  0 siblings, 1 reply; 6+ messages in thread
From: Jonathan Cameron @ 2021-03-07 11:59 UTC (permalink / raw)
  To: Enric Balletbo i Serra
  Cc: Alexandru Ardelean, linux-kernel, linux-iio, bleung, groeck,
	gwendal, Alexandru Ardelean

On Tue, 2 Mar 2021 11:46:06 +0100
Enric Balletbo i Serra <enric.balletbo@collabora.com> wrote:

> Hi all,
> 
> On 21/2/21 17:29, Jonathan Cameron wrote:
> > On Mon, 23 Nov 2020 16:40:16 +0200
> > Alexandru Ardelean <alexandru.ardelean@analog.com> wrote:
> >   
> >> This whole code-block was put under one big if() condition/block.
> >> This change does an early return if the 'physical_device' boolean is false,
> >> thus unindenting the block by one level.
> >>
> >> No other functional change has been done.
> >>
> >> Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com>  
> > @Gwendal, others  This series from Alex has been outstanding for a while
> > but may well still apply.
> > Ideally looking for an ack.
> >   
> 
> This looks good to me.
> 
> Acked-by: Enric Balletbo i Serra <enric.balletbo@collabora.com>

Hi Enric, Ack or both patches or just this one?

@Alex, series needs a rebase.  I'm not totally sure what's changed.
If you don't get to it I'll do it at somepoint but unlikely to
be terribly soon!

Jonathan

> 
> Thanks,
>  Enric
> 
> > Thanks,
> > 
> > Jonathan
> >    
> >> ---
> >>  .../cros_ec_sensors/cros_ec_sensors_core.c    | 161 +++++++++---------
> >>  1 file changed, 81 insertions(+), 80 deletions(-)
> >>
> >> diff --git a/drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c b/drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c
> >> index 5c6c4e6fec9b..9470014936f2 100644
> >> --- a/drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c
> >> +++ b/drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c
> >> @@ -287,89 +287,90 @@ int cros_ec_sensors_core_init(struct platform_device *pdev,
> >>  
> >>  	indio_dev->name = pdev->name;
> >>  
> >> -	if (physical_device) {
> >> -		state->param.cmd = MOTIONSENSE_CMD_INFO;
> >> -		state->param.info.sensor_num = sensor_platform->sensor_num;
> >> -		ret = cros_ec_motion_send_host_cmd(state, 0);
> >> -		if (ret) {
> >> -			dev_warn(dev, "Can not access sensor info\n");
> >> +	if (!physical_device)
> >> +		return 0;
> >> +
> >> +	state->param.cmd = MOTIONSENSE_CMD_INFO;
> >> +	state->param.info.sensor_num = sensor_platform->sensor_num;
> >> +	ret = cros_ec_motion_send_host_cmd(state, 0);
> >> +	if (ret) {
> >> +		dev_warn(dev, "Can not access sensor info\n");
> >> +		return ret;
> >> +	}
> >> +	state->type = state->resp->info.type;
> >> +	state->loc = state->resp->info.location;
> >> +
> >> +	/* Set sign vector, only used for backward compatibility. */
> >> +	memset(state->sign, 1, CROS_EC_SENSOR_MAX_AXIS);
> >> +
> >> +	for (i = CROS_EC_SENSOR_X; i < CROS_EC_SENSOR_MAX_AXIS; i++)
> >> +		state->calib[i].scale = MOTION_SENSE_DEFAULT_SCALE;
> >> +
> >> +	/* 0 is a correct value used to stop the device */
> >> +	if (state->msg->version < 3) {
> >> +		get_default_min_max_freq(state->resp->info.type,
> >> +					 &frequencies[1],
> >> +					 &frequencies[2],
> >> +					 &state->fifo_max_event_count);
> >> +	} else {
> >> +		frequencies[1] = state->resp->info_3.min_frequency;
> >> +		frequencies[2] = state->resp->info_3.max_frequency;
> >> +		state->fifo_max_event_count =
> >> +		    state->resp->info_3.fifo_max_event_count;
> >> +	}
> >> +	for (i = 0; i < ARRAY_SIZE(frequencies); i++) {
> >> +		state->frequencies[2 * i] = frequencies[i] / 1000;
> >> +		state->frequencies[2 * i + 1] =
> >> +			(frequencies[i] % 1000) * 1000;
> >> +	}
> >> +
> >> +	if (cros_ec_check_features(ec, EC_FEATURE_MOTION_SENSE_FIFO)) {
> >> +		/*
> >> +		 * Create a software buffer, feed by the EC FIFO.
> >> +		 * We can not use trigger here, as events are generated
> >> +		 * as soon as sample_frequency is set.
> >> +		 */
> >> +		struct iio_buffer *buffer;
> >> +
> >> +		buffer = devm_iio_kfifo_allocate(dev);
> >> +		if (!buffer)
> >> +			return -ENOMEM;
> >> +
> >> +		iio_device_attach_buffer(indio_dev, buffer);
> >> +		indio_dev->modes = INDIO_BUFFER_SOFTWARE;
> >> +
> >> +		ret = cros_ec_sensorhub_register_push_data(
> >> +				sensor_hub, sensor_platform->sensor_num,
> >> +				indio_dev, push_data);
> >> +		if (ret)
> >>  			return ret;
> >> -		}
> >> -		state->type = state->resp->info.type;
> >> -		state->loc = state->resp->info.location;
> >>  
> >> -		/* Set sign vector, only used for backward compatibility. */
> >> -		memset(state->sign, 1, CROS_EC_SENSOR_MAX_AXIS);
> >> +		ret = devm_add_action_or_reset(
> >> +				dev, cros_ec_sensors_core_clean, pdev);
> >> +		if (ret)
> >> +			return ret;
> >>  
> >> -		for (i = CROS_EC_SENSOR_X; i < CROS_EC_SENSOR_MAX_AXIS; i++)
> >> -			state->calib[i].scale = MOTION_SENSE_DEFAULT_SCALE;
> >> -
> >> -		/* 0 is a correct value used to stop the device */
> >> -		if (state->msg->version < 3) {
> >> -			get_default_min_max_freq(state->resp->info.type,
> >> -						 &frequencies[1],
> >> -						 &frequencies[2],
> >> -						 &state->fifo_max_event_count);
> >> -		} else {
> >> -			frequencies[1] = state->resp->info_3.min_frequency;
> >> -			frequencies[2] = state->resp->info_3.max_frequency;
> >> -			state->fifo_max_event_count =
> >> -			    state->resp->info_3.fifo_max_event_count;
> >> -		}
> >> -		for (i = 0; i < ARRAY_SIZE(frequencies); i++) {
> >> -			state->frequencies[2 * i] = frequencies[i] / 1000;
> >> -			state->frequencies[2 * i + 1] =
> >> -				(frequencies[i] % 1000) * 1000;
> >> -		}
> >> -
> >> -		if (cros_ec_check_features(ec, EC_FEATURE_MOTION_SENSE_FIFO)) {
> >> -			/*
> >> -			 * Create a software buffer, feed by the EC FIFO.
> >> -			 * We can not use trigger here, as events are generated
> >> -			 * as soon as sample_frequency is set.
> >> -			 */
> >> -			struct iio_buffer *buffer;
> >> -
> >> -			buffer = devm_iio_kfifo_allocate(dev);
> >> -			if (!buffer)
> >> -				return -ENOMEM;
> >> -
> >> -			iio_device_attach_buffer(indio_dev, buffer);
> >> -			indio_dev->modes = INDIO_BUFFER_SOFTWARE;
> >> -
> >> -			ret = cros_ec_sensorhub_register_push_data(
> >> -					sensor_hub, sensor_platform->sensor_num,
> >> -					indio_dev, push_data);
> >> -			if (ret)
> >> -				return ret;
> >> -
> >> -			ret = devm_add_action_or_reset(
> >> -					dev, cros_ec_sensors_core_clean, pdev);
> >> -			if (ret)
> >> -				return ret;
> >> -
> >> -			/* Timestamp coming from FIFO are in ns since boot. */
> >> -			ret = iio_device_set_clock(indio_dev, CLOCK_BOOTTIME);
> >> -			if (ret)
> >> -				return ret;
> >> -		} else {
> >> -			const struct attribute **fifo_attrs;
> >> -
> >> -			if (has_hw_fifo)
> >> -				fifo_attrs = cros_ec_sensor_fifo_attributes;
> >> -			else
> >> -				fifo_attrs = NULL;
> >> -
> >> -			/*
> >> -			 * The only way to get samples in buffer is to set a
> >> -			 * software trigger (systrig, hrtimer).
> >> -			 */
> >> -			ret = devm_iio_triggered_buffer_setup_ext(
> >> -					dev, indio_dev, NULL, trigger_capture,
> >> -					NULL, fifo_attrs);
> >> -			if (ret)
> >> -				return ret;
> >> -		}
> >> +		/* Timestamp coming from FIFO are in ns since boot. */
> >> +		ret = iio_device_set_clock(indio_dev, CLOCK_BOOTTIME);
> >> +		if (ret)
> >> +			return ret;
> >> +	} else {
> >> +		const struct attribute **fifo_attrs;
> >> +
> >> +		if (has_hw_fifo)
> >> +			fifo_attrs = cros_ec_sensor_fifo_attributes;
> >> +		else
> >> +			fifo_attrs = NULL;
> >> +
> >> +		/*
> >> +		 * The only way to get samples in buffer is to set a
> >> +		 * software trigger (systrig, hrtimer).
> >> +		 */
> >> +		ret = devm_iio_triggered_buffer_setup_ext(
> >> +				dev, indio_dev, NULL, trigger_capture,
> >> +				NULL, fifo_attrs);
> >> +		if (ret)
> >> +			return ret;
> >>  	}
> >>  
> >>  	return 0;  
> >   


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/2] iio: cros_ec: do an early exit if not physical_device case
  2021-03-07 11:59     ` Jonathan Cameron
@ 2021-03-07 18:45       ` Alexandru Ardelean
  0 siblings, 0 replies; 6+ messages in thread
From: Alexandru Ardelean @ 2021-03-07 18:45 UTC (permalink / raw)
  To: Jonathan Cameron
  Cc: Enric Balletbo i Serra, Alexandru Ardelean, LKML, linux-iio,
	Benson Leung, groeck, Gwendal Grignou

On Sun, Mar 7, 2021 at 1:59 PM Jonathan Cameron <jic23@kernel.org> wrote:
>
> On Tue, 2 Mar 2021 11:46:06 +0100
> Enric Balletbo i Serra <enric.balletbo@collabora.com> wrote:
>
> > Hi all,
> >
> > On 21/2/21 17:29, Jonathan Cameron wrote:
> > > On Mon, 23 Nov 2020 16:40:16 +0200
> > > Alexandru Ardelean <alexandru.ardelean@analog.com> wrote:
> > >
> > >> This whole code-block was put under one big if() condition/block.
> > >> This change does an early return if the 'physical_device' boolean is false,
> > >> thus unindenting the block by one level.
> > >>
> > >> No other functional change has been done.
> > >>
> > >> Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com>
> > > @Gwendal, others  This series from Alex has been outstanding for a while
> > > but may well still apply.
> > > Ideally looking for an ack.
> > >
> >
> > This looks good to me.
> >
> > Acked-by: Enric Balletbo i Serra <enric.balletbo@collabora.com>
>
> Hi Enric, Ack or both patches or just this one?
>
> @Alex, series needs a rebase.  I'm not totally sure what's changed.
> If you don't get to it I'll do it at somepoint but unlikely to
> be terribly soon!

It's likely that it's that iio_device_attach_buffer() went away and
the block got replaced by devm_iio_kfifo_buffer_setup().
I'll re-spin it.
I dropped this set from my main work branch because I didn't know if
it was forgotten, and rebasing it with every change on
devm_iio_kfifo_buffer_setup() and
devm_iio_triggered_buffer_setup_ext() became annoying.
But it shouldn't be hard to re-spin.

>
> Jonathan
>
> >
> > Thanks,
> >  Enric
> >
> > > Thanks,
> > >
> > > Jonathan
> > >
> > >> ---
> > >>  .../cros_ec_sensors/cros_ec_sensors_core.c    | 161 +++++++++---------
> > >>  1 file changed, 81 insertions(+), 80 deletions(-)
> > >>
> > >> diff --git a/drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c b/drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c
> > >> index 5c6c4e6fec9b..9470014936f2 100644
> > >> --- a/drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c
> > >> +++ b/drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c
> > >> @@ -287,89 +287,90 @@ int cros_ec_sensors_core_init(struct platform_device *pdev,
> > >>
> > >>    indio_dev->name = pdev->name;
> > >>
> > >> -  if (physical_device) {
> > >> -          state->param.cmd = MOTIONSENSE_CMD_INFO;
> > >> -          state->param.info.sensor_num = sensor_platform->sensor_num;
> > >> -          ret = cros_ec_motion_send_host_cmd(state, 0);
> > >> -          if (ret) {
> > >> -                  dev_warn(dev, "Can not access sensor info\n");
> > >> +  if (!physical_device)
> > >> +          return 0;
> > >> +
> > >> +  state->param.cmd = MOTIONSENSE_CMD_INFO;
> > >> +  state->param.info.sensor_num = sensor_platform->sensor_num;
> > >> +  ret = cros_ec_motion_send_host_cmd(state, 0);
> > >> +  if (ret) {
> > >> +          dev_warn(dev, "Can not access sensor info\n");
> > >> +          return ret;
> > >> +  }
> > >> +  state->type = state->resp->info.type;
> > >> +  state->loc = state->resp->info.location;
> > >> +
> > >> +  /* Set sign vector, only used for backward compatibility. */
> > >> +  memset(state->sign, 1, CROS_EC_SENSOR_MAX_AXIS);
> > >> +
> > >> +  for (i = CROS_EC_SENSOR_X; i < CROS_EC_SENSOR_MAX_AXIS; i++)
> > >> +          state->calib[i].scale = MOTION_SENSE_DEFAULT_SCALE;
> > >> +
> > >> +  /* 0 is a correct value used to stop the device */
> > >> +  if (state->msg->version < 3) {
> > >> +          get_default_min_max_freq(state->resp->info.type,
> > >> +                                   &frequencies[1],
> > >> +                                   &frequencies[2],
> > >> +                                   &state->fifo_max_event_count);
> > >> +  } else {
> > >> +          frequencies[1] = state->resp->info_3.min_frequency;
> > >> +          frequencies[2] = state->resp->info_3.max_frequency;
> > >> +          state->fifo_max_event_count =
> > >> +              state->resp->info_3.fifo_max_event_count;
> > >> +  }
> > >> +  for (i = 0; i < ARRAY_SIZE(frequencies); i++) {
> > >> +          state->frequencies[2 * i] = frequencies[i] / 1000;
> > >> +          state->frequencies[2 * i + 1] =
> > >> +                  (frequencies[i] % 1000) * 1000;
> > >> +  }
> > >> +
> > >> +  if (cros_ec_check_features(ec, EC_FEATURE_MOTION_SENSE_FIFO)) {
> > >> +          /*
> > >> +           * Create a software buffer, feed by the EC FIFO.
> > >> +           * We can not use trigger here, as events are generated
> > >> +           * as soon as sample_frequency is set.
> > >> +           */
> > >> +          struct iio_buffer *buffer;
> > >> +
> > >> +          buffer = devm_iio_kfifo_allocate(dev);
> > >> +          if (!buffer)
> > >> +                  return -ENOMEM;
> > >> +
> > >> +          iio_device_attach_buffer(indio_dev, buffer);
> > >> +          indio_dev->modes = INDIO_BUFFER_SOFTWARE;
> > >> +
> > >> +          ret = cros_ec_sensorhub_register_push_data(
> > >> +                          sensor_hub, sensor_platform->sensor_num,
> > >> +                          indio_dev, push_data);
> > >> +          if (ret)
> > >>                    return ret;
> > >> -          }
> > >> -          state->type = state->resp->info.type;
> > >> -          state->loc = state->resp->info.location;
> > >>
> > >> -          /* Set sign vector, only used for backward compatibility. */
> > >> -          memset(state->sign, 1, CROS_EC_SENSOR_MAX_AXIS);
> > >> +          ret = devm_add_action_or_reset(
> > >> +                          dev, cros_ec_sensors_core_clean, pdev);
> > >> +          if (ret)
> > >> +                  return ret;
> > >>
> > >> -          for (i = CROS_EC_SENSOR_X; i < CROS_EC_SENSOR_MAX_AXIS; i++)
> > >> -                  state->calib[i].scale = MOTION_SENSE_DEFAULT_SCALE;
> > >> -
> > >> -          /* 0 is a correct value used to stop the device */
> > >> -          if (state->msg->version < 3) {
> > >> -                  get_default_min_max_freq(state->resp->info.type,
> > >> -                                           &frequencies[1],
> > >> -                                           &frequencies[2],
> > >> -                                           &state->fifo_max_event_count);
> > >> -          } else {
> > >> -                  frequencies[1] = state->resp->info_3.min_frequency;
> > >> -                  frequencies[2] = state->resp->info_3.max_frequency;
> > >> -                  state->fifo_max_event_count =
> > >> -                      state->resp->info_3.fifo_max_event_count;
> > >> -          }
> > >> -          for (i = 0; i < ARRAY_SIZE(frequencies); i++) {
> > >> -                  state->frequencies[2 * i] = frequencies[i] / 1000;
> > >> -                  state->frequencies[2 * i + 1] =
> > >> -                          (frequencies[i] % 1000) * 1000;
> > >> -          }
> > >> -
> > >> -          if (cros_ec_check_features(ec, EC_FEATURE_MOTION_SENSE_FIFO)) {
> > >> -                  /*
> > >> -                   * Create a software buffer, feed by the EC FIFO.
> > >> -                   * We can not use trigger here, as events are generated
> > >> -                   * as soon as sample_frequency is set.
> > >> -                   */
> > >> -                  struct iio_buffer *buffer;
> > >> -
> > >> -                  buffer = devm_iio_kfifo_allocate(dev);
> > >> -                  if (!buffer)
> > >> -                          return -ENOMEM;
> > >> -
> > >> -                  iio_device_attach_buffer(indio_dev, buffer);
> > >> -                  indio_dev->modes = INDIO_BUFFER_SOFTWARE;
> > >> -
> > >> -                  ret = cros_ec_sensorhub_register_push_data(
> > >> -                                  sensor_hub, sensor_platform->sensor_num,
> > >> -                                  indio_dev, push_data);
> > >> -                  if (ret)
> > >> -                          return ret;
> > >> -
> > >> -                  ret = devm_add_action_or_reset(
> > >> -                                  dev, cros_ec_sensors_core_clean, pdev);
> > >> -                  if (ret)
> > >> -                          return ret;
> > >> -
> > >> -                  /* Timestamp coming from FIFO are in ns since boot. */
> > >> -                  ret = iio_device_set_clock(indio_dev, CLOCK_BOOTTIME);
> > >> -                  if (ret)
> > >> -                          return ret;
> > >> -          } else {
> > >> -                  const struct attribute **fifo_attrs;
> > >> -
> > >> -                  if (has_hw_fifo)
> > >> -                          fifo_attrs = cros_ec_sensor_fifo_attributes;
> > >> -                  else
> > >> -                          fifo_attrs = NULL;
> > >> -
> > >> -                  /*
> > >> -                   * The only way to get samples in buffer is to set a
> > >> -                   * software trigger (systrig, hrtimer).
> > >> -                   */
> > >> -                  ret = devm_iio_triggered_buffer_setup_ext(
> > >> -                                  dev, indio_dev, NULL, trigger_capture,
> > >> -                                  NULL, fifo_attrs);
> > >> -                  if (ret)
> > >> -                          return ret;
> > >> -          }
> > >> +          /* Timestamp coming from FIFO are in ns since boot. */
> > >> +          ret = iio_device_set_clock(indio_dev, CLOCK_BOOTTIME);
> > >> +          if (ret)
> > >> +                  return ret;
> > >> +  } else {
> > >> +          const struct attribute **fifo_attrs;
> > >> +
> > >> +          if (has_hw_fifo)
> > >> +                  fifo_attrs = cros_ec_sensor_fifo_attributes;
> > >> +          else
> > >> +                  fifo_attrs = NULL;
> > >> +
> > >> +          /*
> > >> +           * The only way to get samples in buffer is to set a
> > >> +           * software trigger (systrig, hrtimer).
> > >> +           */
> > >> +          ret = devm_iio_triggered_buffer_setup_ext(
> > >> +                          dev, indio_dev, NULL, trigger_capture,
> > >> +                          NULL, fifo_attrs);
> > >> +          if (ret)
> > >> +                  return ret;
> > >>    }
> > >>
> > >>    return 0;
> > >
>

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2021-03-07 18:47 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-23 14:40 [PATCH 1/2] iio: cros_ec: do an early exit if not physical_device case Alexandru Ardelean
2020-11-23 14:40 ` [PATCH 2/2] iio: cros_ec: un-indent block that configures motion sensor fifo Alexandru Ardelean
2021-02-21 16:29 ` [PATCH 1/2] iio: cros_ec: do an early exit if not physical_device case Jonathan Cameron
2021-03-02 10:46   ` Enric Balletbo i Serra
2021-03-07 11:59     ` Jonathan Cameron
2021-03-07 18:45       ` Alexandru Ardelean

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.