From: Enric Balletbo Serra <eballetbo@gmail.com>
To: Gwendal Grignou <gwendal@chromium.org>
Cc: Brian Norris <briannorris@chromium.org>,
Jonathan Cameron <jic23@kernel.org>,
Hartmut Knaack <knaack.h@gmx.de>,
Lars-Peter Clausen <lars@metafoo.de>,
Peter Meerwald-Stadler <pmeerw@pmeerw.net>,
Lee Jones <lee.jones@linaro.org>,
Benson Leung <bleung@chromium.org>,
Enric Balletbo i Serra <enric.balletbo@collabora.com>,
Doug Anderson <dianders@chromium.org>,
Guenter Roeck <groeck@chromium.org>,
Fabien Lahoudere <fabien.lahoudere@collabora.com>,
linux-kernel <linux-kernel@vger.kernel.org>,
linux-iio <linux-iio@vger.kernel.org>
Subject: Re: [PATCH v4 01/17] mfd: cros_ec: Add sensor_count and make check_features public
Date: Fri, 8 Nov 2019 23:03:56 +0100 [thread overview]
Message-ID: <CAFqH_50q7y-sL0SyA3BDkZ9_YBX_FL90smtXt7v0Z+BW8nrw3A@mail.gmail.com> (raw)
In-Reply-To: <20191105222652.70226-2-gwendal@chromium.org>
Missatge de Gwendal Grignou <gwendal@chromium.org> del dia dt., 5 de
nov. 2019 a les 23:28:
>
> Add a new function to return the number of MEMS sensors available in a
> ChromeOS Embedded Controller.
> It uses MOTIONSENSE_CMD_DUMP if available or a specific memory map ACPI
> registers to find out.
>
> Also, make check_features public as it can be useful for other drivers
> to know what the Embedded Controller supports.
>
> Signed-off-by: Gwendal Grignou <gwendal@chromium.org>
Version 3 was acked and I think we can maintain his ack, so:
Acked-for-MFD-by: Lee Jones <lee.jones@linaro.org>
Also,
Acked-by: Enric Balletbo i Serra <enric.balletbo@collabora.com>
Lee, how you would like to handle this? I think will be safe for
patches 1/2/3 go through the platform-chrome tree without an immutable
branch. Patch 3 thought still needs and Ack from you if is fine.
Thanks,
Enric
> ---
> Changes in v4:
> Check patch with --strict option
> Use sizeof(*obj) instead of sizeof(struct ...obj)
> Alignement
> Remove useless ().
> Changes in v3:
> Fix doxygen comments.
> Changes in v2:
> Fix spelling in commit message.
> Cleanup the case where DUMP command is not supported.
> Move code from mfd to platform/chrome/
>
> drivers/mfd/cros_ec_dev.c | 32 ------
> drivers/platform/chrome/cros_ec_proto.c | 117 ++++++++++++++++++++
> include/linux/platform_data/cros_ec_proto.h | 5 +
> 3 files changed, 122 insertions(+), 32 deletions(-)
>
> diff --git a/drivers/mfd/cros_ec_dev.c b/drivers/mfd/cros_ec_dev.c
> index 6e6dfd6c1871..a35104e35cb4 100644
> --- a/drivers/mfd/cros_ec_dev.c
> +++ b/drivers/mfd/cros_ec_dev.c
> @@ -112,38 +112,6 @@ static const struct mfd_cell cros_ec_vbc_cells[] = {
> { .name = "cros-ec-vbc", }
> };
>
> -static int cros_ec_check_features(struct cros_ec_dev *ec, int feature)
> -{
> - struct cros_ec_command *msg;
> - int ret;
> -
> - if (ec->features[0] == -1U && ec->features[1] == -1U) {
> - /* features bitmap not read yet */
> - msg = kzalloc(sizeof(*msg) + sizeof(ec->features), GFP_KERNEL);
> - if (!msg)
> - return -ENOMEM;
> -
> - msg->command = EC_CMD_GET_FEATURES + ec->cmd_offset;
> - msg->insize = sizeof(ec->features);
> -
> - ret = cros_ec_cmd_xfer_status(ec->ec_dev, msg);
> - if (ret < 0) {
> - dev_warn(ec->dev, "cannot get EC features: %d/%d\n",
> - ret, msg->result);
> - memset(ec->features, 0, sizeof(ec->features));
> - } else {
> - memcpy(ec->features, msg->data, sizeof(ec->features));
> - }
> -
> - dev_dbg(ec->dev, "EC features %08x %08x\n",
> - ec->features[0], ec->features[1]);
> -
> - kfree(msg);
> - }
> -
> - return ec->features[feature / 32] & EC_FEATURE_MASK_0(feature);
> -}
> -
> static void cros_ec_class_release(struct device *dev)
> {
> kfree(to_cros_ec_dev(dev));
> diff --git a/drivers/platform/chrome/cros_ec_proto.c b/drivers/platform/chrome/cros_ec_proto.c
> index 7db58771ec77..b502933e911b 100644
> --- a/drivers/platform/chrome/cros_ec_proto.c
> +++ b/drivers/platform/chrome/cros_ec_proto.c
> @@ -717,3 +717,120 @@ u32 cros_ec_get_host_event(struct cros_ec_device *ec_dev)
> return host_event;
> }
> EXPORT_SYMBOL(cros_ec_get_host_event);
> +
> +/**
> + * cros_ec_check_features - Test for the presence of EC features
> + *
> + * @ec: EC device, does not have to be connected directly to the AP,
> + * can be daisy chained through another device.
> + * @feature: One of ec_feature_code bit.
> + *
> + * Call this function to test whether the ChromeOS EC supports a feature.
> + *
> + * Return: 1 if supported, 0 if not
> + */
> +int cros_ec_check_features(struct cros_ec_dev *ec, int feature)
> +{
> + struct cros_ec_command *msg;
> + int ret;
> +
> + if (ec->features[0] == -1U && ec->features[1] == -1U) {
> + /* features bitmap not read yet */
> + msg = kzalloc(sizeof(*msg) + sizeof(ec->features), GFP_KERNEL);
> + if (!msg)
> + return -ENOMEM;
> +
> + msg->command = EC_CMD_GET_FEATURES + ec->cmd_offset;
> + msg->insize = sizeof(ec->features);
> +
> + ret = cros_ec_cmd_xfer_status(ec->ec_dev, msg);
> + if (ret < 0) {
> + dev_warn(ec->dev, "cannot get EC features: %d/%d\n",
> + ret, msg->result);
> + memset(ec->features, 0, sizeof(ec->features));
> + } else {
> + memcpy(ec->features, msg->data, sizeof(ec->features));
> + }
> +
> + dev_dbg(ec->dev, "EC features %08x %08x\n",
> + ec->features[0], ec->features[1]);
> +
> + kfree(msg);
> + }
> +
> + return ec->features[feature / 32] & EC_FEATURE_MASK_0(feature);
> +}
> +EXPORT_SYMBOL_GPL(cros_ec_check_features);
> +
> +/**
> + * cros_ec_get_sensor_count - Return the number of MEMS sensors supported.
> + *
> + * @ec: EC device, does not have to be connected directly to the AP,
> + * can be daisy chained through another device.
> + * Return: < 0 in case of error.
> + */
> +int cros_ec_get_sensor_count(struct cros_ec_dev *ec)
> +{
> + /*
> + * Issue a command to get the number of sensor reported.
> + * If not supported, check for legacy mode.
> + */
> + int ret, sensor_count;
> + struct ec_params_motion_sense *params;
> + struct ec_response_motion_sense *resp;
> + struct cros_ec_command *msg;
> + struct cros_ec_device *ec_dev = ec->ec_dev;
> + u8 status;
> +
> + msg = kzalloc(sizeof(*msg) + max(sizeof(*params), sizeof(*resp)),
> + GFP_KERNEL);
> + if (!msg)
> + return -ENOMEM;
> +
> + msg->version = 1;
> + msg->command = EC_CMD_MOTION_SENSE_CMD + ec->cmd_offset;
> + msg->outsize = sizeof(*params);
> + msg->insize = sizeof(*resp);
> +
> + params = (struct ec_params_motion_sense *)msg->data;
> + params->cmd = MOTIONSENSE_CMD_DUMP;
> +
> + ret = cros_ec_cmd_xfer(ec->ec_dev, msg);
> + if (ret < 0) {
> + sensor_count = ret;
> + } else if (msg->result != EC_RES_SUCCESS) {
> + sensor_count = -EPROTO;
> + } else {
> + resp = (struct ec_response_motion_sense *)msg->data;
> + sensor_count = resp->dump.sensor_count;
> + }
> + kfree(msg);
> +
> + /*
> + * Check legacy mode: Let's find out if sensors are accessible
> + * via LPC interface.
> + */
> + if (sensor_count == -EPROTO &&
> + ec->cmd_offset == 0 &&
> + ec_dev->cmd_readmem) {
> + ret = ec_dev->cmd_readmem(ec_dev, EC_MEMMAP_ACC_STATUS,
> + 1, &status);
> + if (ret >= 0 &&
> + (status & EC_MEMMAP_ACC_STATUS_PRESENCE_BIT)) {
> + /*
> + * We have 2 sensors, one in the lid, one in the base.
> + */
> + sensor_count = 2;
> + } else {
> + /*
> + * EC uses LPC interface and no sensors are presented.
> + */
> + sensor_count = 0;
> + }
> + } else if (sensor_count == -EPROTO) {
> + /* EC responded, but does not understand DUMP command. */
> + sensor_count = 0;
> + }
> + return sensor_count;
> +}
> +EXPORT_SYMBOL_GPL(cros_ec_get_sensor_count);
> diff --git a/include/linux/platform_data/cros_ec_proto.h b/include/linux/platform_data/cros_ec_proto.h
> index 0d4e4aaed37a..f3de0662135d 100644
> --- a/include/linux/platform_data/cros_ec_proto.h
> +++ b/include/linux/platform_data/cros_ec_proto.h
> @@ -12,6 +12,7 @@
> #include <linux/mutex.h>
> #include <linux/notifier.h>
>
> +#include <linux/mfd/cros_ec.h>
> #include <linux/platform_data/cros_ec_commands.h>
>
> #define CROS_EC_DEV_NAME "cros_ec"
> @@ -213,4 +214,8 @@ int cros_ec_get_next_event(struct cros_ec_device *ec_dev, bool *wake_event);
>
> u32 cros_ec_get_host_event(struct cros_ec_device *ec_dev);
>
> +int cros_ec_check_features(struct cros_ec_dev *ec, int feature);
> +
> +int cros_ec_get_sensor_count(struct cros_ec_dev *ec);
> +
> #endif /* __LINUX_CROS_EC_PROTO_H */
> --
> 2.24.0.rc1.363.gb1bccd3e3d-goog
>
next prev parent reply other threads:[~2019-11-08 22:04 UTC|newest]
Thread overview: 52+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-11-05 22:26 [PATCH v4 00/17] cros_ec: Add sensorhub driver and FIFO processing Gwendal Grignou
2019-11-05 22:26 ` [PATCH v4 01/17] mfd: cros_ec: Add sensor_count and make check_features public Gwendal Grignou
2019-11-08 22:03 ` Enric Balletbo Serra [this message]
2019-11-11 11:44 ` Lee Jones
2019-11-16 11:49 ` Jonathan Cameron
2019-11-05 22:26 ` [PATCH v4 02/17] platform: cros_ec: Add cros_ec_sensor_hub driver Gwendal Grignou
2019-11-10 12:10 ` Jonathan Cameron
2019-11-11 9:24 ` Enric Balletbo i Serra
2019-11-11 11:55 ` Jonathan Cameron
2019-11-05 22:26 ` [PATCH v4 03/17] platform/mfd:iio: cros_ec: Register sensor through sensorhub Gwendal Grignou
2019-11-10 12:13 ` Jonathan Cameron
2019-11-11 9:25 ` Enric Balletbo i Serra
2019-11-11 11:43 ` Lee Jones
2019-11-05 22:26 ` [PATCH v4 04/17] platform: chrome: cros-ec: record event timestamp in the hard irq Gwendal Grignou
2019-11-10 12:16 ` Jonathan Cameron
2019-11-11 9:27 ` Enric Balletbo i Serra
2019-11-05 22:26 ` [PATCH v4 05/17] platform: chrome: cros_ec: Do not attempt to register a non-positive IRQ number Gwendal Grignou
2019-11-10 12:17 ` Jonathan Cameron
2019-11-11 9:29 ` Enric Balletbo i Serra
2019-11-14 0:58 ` Gwendal Grignou
2019-11-05 22:26 ` [PATCH v4 06/17] platform: chrome: cros_ec: handle MKBP more events flag Gwendal Grignou
2019-11-10 12:28 ` Jonathan Cameron
2019-11-11 9:30 ` Enric Balletbo i Serra
2019-11-05 22:26 ` [PATCH v4 07/17] Revert "Input: cros_ec_keyb - add back missing mask for event_type" Gwendal Grignou
2019-11-11 9:20 ` Enric Balletbo i Serra
2019-11-11 19:23 ` Dmitry Torokhov
2019-11-05 22:26 ` [PATCH v4 08/17] Revert "Input: cros_ec_keyb: mask out extra flags in event_type" Gwendal Grignou
2019-11-11 9:20 ` Enric Balletbo i Serra
2019-11-11 19:23 ` Dmitry Torokhov
2019-11-05 22:26 ` [PATCH v4 09/17] platform: chrome: sensorhub: Add FIFO support Gwendal Grignou
2019-11-06 21:13 ` Gwendal Grignou
2019-11-10 12:54 ` Jonathan Cameron
2019-11-14 1:01 ` Gwendal Grignou
2019-11-05 22:26 ` [PATCH v4 10/17] platform: chrome: sensorhub: Add code to spread timestmap Gwendal Grignou
2019-11-10 12:57 ` Jonathan Cameron
2019-11-05 22:26 ` [PATCH v4 11/17] platform: chrome: sensorhub: Add median filter Gwendal Grignou
2019-11-10 13:07 ` Jonathan Cameron
2019-11-05 22:26 ` [PATCH v4 12/17] iio: cros_ec: Move function description to .c file Gwendal Grignou
2019-11-10 13:08 ` Jonathan Cameron
2019-11-11 9:35 ` Enric Balletbo i Serra
2019-11-05 22:26 ` [PATCH v4 13/17] iio: cros_ec: Register to cros_ec_sensorhub when EC supports FIFO Gwendal Grignou
2019-11-10 13:17 ` Jonathan Cameron
2019-11-14 18:17 ` Gwendal Grignou
2019-11-05 22:26 ` [PATCH v4 14/17] iio: cros_ec: Remove pm function Gwendal Grignou
2019-11-10 13:18 ` Jonathan Cameron
2019-11-11 9:37 ` Enric Balletbo i Serra
2019-11-05 22:26 ` [PATCH v4 15/17] iio: cros_ec: Expose hwfifo_timeout Gwendal Grignou
2019-11-10 13:21 ` Jonathan Cameron
2019-11-05 22:26 ` [PATCH v4 16/17] iio: cros_ec: Report hwfifo_watermark_max Gwendal Grignou
2019-11-10 13:22 ` Jonathan Cameron
2019-11-05 22:26 ` [PATCH v4 17/17] iio: cros_ec: Use Hertz as unit for sampling frequency Gwendal Grignou
2019-11-10 13:24 ` Jonathan Cameron
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=CAFqH_50q7y-sL0SyA3BDkZ9_YBX_FL90smtXt7v0Z+BW8nrw3A@mail.gmail.com \
--to=eballetbo@gmail.com \
--cc=bleung@chromium.org \
--cc=briannorris@chromium.org \
--cc=dianders@chromium.org \
--cc=enric.balletbo@collabora.com \
--cc=fabien.lahoudere@collabora.com \
--cc=groeck@chromium.org \
--cc=gwendal@chromium.org \
--cc=jic23@kernel.org \
--cc=knaack.h@gmx.de \
--cc=lars@metafoo.de \
--cc=lee.jones@linaro.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).