All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Fabien Lahoudere <fabien.lahoudere@collabora.com>
Cc: kernel@collabora.com, Nick Vaccaro <nvaccaro@chromium.org>,
	Hartmut Knaack <knaack.h@gmx.de>,
	Lars-Peter Clausen <lars@metafoo.de>,
	Peter Meerwald-Stadler <pmeerw@pmeerw.net>,
	linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v3 6/8] iio: common: cros_ec_sensors: support protocol v3 message
Date: Sat, 22 Jun 2019 11:15:09 +0100	[thread overview]
Message-ID: <20190622111509.314d25bf@archlinux> (raw)
In-Reply-To: <ac3cdc104e59565d178dfa86f2727045224dc4da.1560848479.git.fabien.lahoudere@collabora.com>

On Tue, 18 Jun 2019 11:06:37 +0200
Fabien Lahoudere <fabien.lahoudere@collabora.com> wrote:

> Version 3 of the EC protocol provides min and max frequencies for EC sensors.
> 
> Signed-off-by: Fabien Lahoudere <fabien.lahoudere@collabora.com>
> Signed-off-by: Nick Vaccaro <nvaccaro@chromium.org>
Looks good to me. I'll pick up next time if no one else raises any
issues on this one.

Thanks,

Jonathan

> ---
>  .../cros_ec_sensors/cros_ec_sensors_core.c    | 85 ++++++++++++++++++-
>  .../linux/iio/common/cros_ec_sensors_core.h   |  3 +
>  2 files changed, 87 insertions(+), 1 deletion(-)
> 
> 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 57034e212fe1..2ce077b576a4 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
> @@ -26,6 +26,66 @@ static char *cros_ec_loc[] = {
>  	[MOTIONSENSE_LOC_MAX] = "unknown",
>  };
>  
> +static void get_default_min_max_freq(enum motionsensor_type type,
> +				     u32 *min_freq,
> +				     u32 *max_freq)
> +{
> +	switch (type) {
> +	case MOTIONSENSE_TYPE_ACCEL:
> +	case MOTIONSENSE_TYPE_GYRO:
> +		*min_freq = 12500;
> +		*max_freq = 100000;
> +		break;
> +	case MOTIONSENSE_TYPE_MAG:
> +		*min_freq = 5000;
> +		*max_freq = 25000;
> +		break;
> +	case MOTIONSENSE_TYPE_PROX:
> +	case MOTIONSENSE_TYPE_LIGHT:
> +		*min_freq = 100;
> +		*max_freq = 50000;
> +		break;
> +	case MOTIONSENSE_TYPE_BARO:
> +		*min_freq = 250;
> +		*max_freq = 20000;
> +		break;
> +	case MOTIONSENSE_TYPE_ACTIVITY:
> +	default:
> +		*min_freq = 0;
> +		*max_freq = 0;
> +		break;
> +	}
> +}
> +
> +static int cros_ec_get_host_cmd_version_mask(struct cros_ec_device *ec_dev,
> +					     u16 cmd_offset, u16 cmd, u32 *mask)
> +{
> +	int ret;
> +	struct {
> +		struct cros_ec_command msg;
> +		union {
> +			struct ec_params_get_cmd_versions params;
> +			struct ec_response_get_cmd_versions resp;
> +		};
> +	} __packed buf = {
> +		.msg = {
> +			.command = EC_CMD_GET_CMD_VERSIONS + cmd_offset,
> +			.insize = sizeof(struct ec_response_get_cmd_versions),
> +			.outsize = sizeof(struct ec_params_get_cmd_versions)
> +			},
> +		.params = {.cmd = cmd}
> +	};
> +
> +	ret = cros_ec_cmd_xfer_status(ec_dev, &buf.msg);
> +	if (ret >= 0) {
> +		if (buf.msg.result == EC_RES_SUCCESS)
> +			*mask = buf.resp.version_mask;
> +		else
> +			*mask = 0;
> +	}
> +	return ret;
> +}
> +
>  int cros_ec_sensors_core_init(struct platform_device *pdev,
>  			      int num_channels,
>  			      bool physical_device)
> @@ -35,6 +95,8 @@ int cros_ec_sensors_core_init(struct platform_device *pdev,
>  	struct cros_ec_dev *ec = dev_get_drvdata(pdev->dev.parent);
>  	struct cros_ec_sensor_platform *sensor_platform = dev_get_platdata(dev);
>  	struct iio_dev *indio_dev;
> +	u32 ver_mask;
> +	int ret;
>  
>  	if (num_channels > CROS_EC_SENSORS_CORE_MAX_CHANNELS)
>  		return -EINVAL;
> @@ -57,8 +119,16 @@ int cros_ec_sensors_core_init(struct platform_device *pdev,
>  
>  	mutex_init(&state->cmd_lock);
>  
> +	/* determine what version of MOTIONSENSE CMD EC has */
> +	ret = cros_ec_get_host_cmd_version_mask(state->ec,
> +						ec->cmd_offset,
> +						EC_CMD_MOTION_SENSE_CMD,
> +						&ver_mask);
> +	if (ret < 0 || ver_mask == 0)
> +		return -ENODEV;
> +
>  	/* Set up the host command structure. */
> -	state->msg->version = 2;
> +	state->msg->version = fls(ver_mask) - 1;
>  	state->msg->command = EC_CMD_MOTION_SENSE_CMD + ec->cmd_offset;
>  	state->msg->outsize = sizeof(struct ec_params_motion_sense);
>  
> @@ -76,6 +146,19 @@ int cros_ec_sensors_core_init(struct platform_device *pdev,
>  		}
>  		state->type = state->resp->info.type;
>  		state->loc = state->resp->info.location;
> +
> +		/* Value to stop the device */
> +		state->frequency_range[0] = 0;
> +		if (state->msg->version < 3) {
> +			get_default_min_max_freq(state->resp->info.type,
> +						 &state->frequency_range[1],
> +						 &state->frequency_range[2]);
> +		} else {
> +			state->frequency_range[1] =
> +			    state->resp->info_3.min_frequency;
> +			state->frequency_range[2] =
> +			    state->resp->info_3.max_frequency;
> +		}
>  	}
>  
>  	indio_dev->info = &state->info;
> diff --git a/include/linux/iio/common/cros_ec_sensors_core.h b/include/linux/iio/common/cros_ec_sensors_core.h
> index 3e6de427076e..89937ad242ef 100644
> --- a/include/linux/iio/common/cros_ec_sensors_core.h
> +++ b/include/linux/iio/common/cros_ec_sensors_core.h
> @@ -74,6 +74,9 @@ struct cros_ec_sensors_core_state {
>  	int curr_sampl_freq;
>  	struct iio_info info;
>  	struct iio_chan_spec channels[CROS_EC_SENSORS_CORE_MAX_CHANNELS];
> +
> +	/* Disable, Min and Max Sampling Frequency in mHz */
> +	int frequency_range[3];
>  };
>  
>  /**


  reply	other threads:[~2019-06-22 10:15 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-18  9:06 [PATCH v3 0/8] Expose cros_ec_sensors frequency range via iio sysfs Fabien Lahoudere
2019-06-18  9:06 ` [PATCH v3 1/8] iio: common: cros_ec_sensors: move iio_info management to core Fabien Lahoudere
2019-06-18  9:06 ` [PATCH v3 2/8] iio: common: cros_ec_sensors: move channels to core structure Fabien Lahoudere
2019-06-22 10:07   ` Jonathan Cameron
2019-06-18  9:06 ` [PATCH v3 3/8] iio: common: cros_ec_sensors: move registration to core Fabien Lahoudere
2019-06-22 10:13   ` Jonathan Cameron
2019-06-22 10:24     ` Jonathan Cameron
2019-06-18  9:06 ` [PATCH v3 4/8] iio: common: cros_ec_sensors: clean code Fabien Lahoudere
2019-06-18  9:06 ` [PATCH v3 5/8] iio: common: cros_ec_sensors: use core structure Fabien Lahoudere
2019-06-22 10:24   ` Jonathan Cameron
2019-06-18  9:06 ` [PATCH v3 6/8] iio: common: cros_ec_sensors: support protocol v3 message Fabien Lahoudere
2019-06-22 10:15   ` Jonathan Cameron [this message]
2019-06-25 17:04     ` Enric Balletbo i Serra
2019-06-27 13:31       ` Fabien Lahoudere
2019-06-18  9:06 ` [PATCH v3 7/8] iio: common: cros_ec_sensors: add sysfs attribute for frequencies Fabien Lahoudere
2019-06-22 10:18   ` Jonathan Cameron
2019-06-18  9:06 ` [PATCH v3 8/8] docs: iio: add precision about sampling_frequency_available Fabien Lahoudere
2019-06-22 10:21   ` Jonathan Cameron
2019-07-09  9:43     ` Fabien Lahoudere
2019-06-19 12:24 ` [PATCH v3 0/8] Expose cros_ec_sensors frequency range via iio sysfs Fabien Lahoudere

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190622111509.314d25bf@archlinux \
    --to=jic23@kernel.org \
    --cc=fabien.lahoudere@collabora.com \
    --cc=kernel@collabora.com \
    --cc=knaack.h@gmx.de \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nvaccaro@chromium.org \
    --cc=pmeerw@pmeerw.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.