From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.1 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6F315C282CE for ; Wed, 22 May 2019 19:10:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3A2A620868 for ; Wed, 22 May 2019 19:10:28 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="OIpjo6Ge" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729740AbfEVTK1 (ORCPT ); Wed, 22 May 2019 15:10:27 -0400 Received: from mail-io1-f65.google.com ([209.85.166.65]:41481 "EHLO mail-io1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729381AbfEVTK1 (ORCPT ); Wed, 22 May 2019 15:10:27 -0400 Received: by mail-io1-f65.google.com with SMTP id a17so2775364iot.8 for ; Wed, 22 May 2019 12:10:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=JztsDPKwVSjjzVFJxCnAodsoYM1sI9+w+KE4psvk3Tw=; b=OIpjo6GeYzLO9N7JZmCf7oLec+d5SKY9HgnRArn+FaQkKjL1vhpuJpfXCRPnVfQPD2 MsBN8zEHotlPHM/SJawlWqqjUHs8UdjfgKyXX9tmINOAmFqKZfgN5U5cDKgni9SJCvFX +ws2LZ8ykSECyBD2fuq4DWKDuMk7aXfkqahIs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=JztsDPKwVSjjzVFJxCnAodsoYM1sI9+w+KE4psvk3Tw=; b=oLCwvG/DPYGoLVkIiclMjHPCwqHk6Nd0SwKUT7ioOnM6kgGxTxfEWpjqBMNykXafW8 qKHOWrc8a+WZ3lgzupZCpMKUR3cII3nkEBxhWrAkAS/2pBKIHDFWfxdcTT5QN8fhljF9 GxrplReJJF9sG13AM+w+r9Erd/T9ibEmD3CD1Lpb/YFUdYf01IV71b0cTqrHCUPJtrAk oSljewGwAqpdRnDBsFWNOhADS9TGtp1HUpWI3sHaKxewB2MLxj4W6LqYio5Zq8/IZ0sk KRYarHe81tIHBn7pgV1vpVWlAWXeQXKCmw/8KPH7DOG0PVFJ+gvH77wUTpudfZiWeAMW GmNg== X-Gm-Message-State: APjAAAUvX2PxCUP8f2t3B5XiQcAJS3MrhmRDxIULQYhk/54Pp5wX3x2B MLwtcpFPjc39s442vFgeDNegPn73i1GeMWPmyQjG3g== X-Google-Smtp-Source: APXvYqw9xWV+KzCJMKkerL3ddFMxInfh9UTBZXl4EYmy+vLwEW6vBMFfst9vJjUYfqb7/Gl5QP1VJGxDKw+tLkerHIA= X-Received: by 2002:a6b:e502:: with SMTP id y2mr34613621ioc.149.1558552225816; Wed, 22 May 2019 12:10:25 -0700 (PDT) MIME-Version: 1.0 References: <9d5dbba798410321177efa5d8a562105ff8cf429.1558533743.git.fabien.lahoudere@collabora.com> In-Reply-To: <9d5dbba798410321177efa5d8a562105ff8cf429.1558533743.git.fabien.lahoudere@collabora.com> From: Gwendal Grignou Date: Wed, 22 May 2019 12:10:14 -0700 Message-ID: Subject: Re: [PATCH 1/3] iio: common: cros_ec_sensors: support protocol v3 message To: Fabien Lahoudere Cc: kernel@collabora.com, Jonathan Cameron , Hartmut Knaack , Lars-Peter Clausen , Peter Meerwald-Stadler , Benson Leung , Enric Balletbo i Serra , Guenter Roeck , Lee Jones , linux-iio@vger.kernel.org, linux-kernel Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Remove CROS_EC_FIFO_SIZE and "u32 fifo_max_event_count;" from the driver/iio/ code. This code is for a driver - cros-ec-sensor-ring - that is not upstreamable. [see http://lkml.iu.edu/hypermail/linux/kernel/1607.2/01335.html]. The EC interface is fine though, we are working on a new version of the driver that can be merged. Gwendal. On Wed, May 22, 2019 at 7:10 AM Fabien Lahoudere wrote: > > Version 3 of the EC protocol provides min and max frequencies and fifo > size for EC sensors. > > Signed-off-by: Fabien Lahoudere > --- > .../cros_ec_sensors/cros_ec_sensors_core.c | 98 ++++++++++++++++++- > .../linux/iio/common/cros_ec_sensors_core.h | 7 ++ > include/linux/mfd/cros_ec_commands.h | 21 ++++ > 3 files changed, 125 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 719a0df5aeeb..d5c8b4714ad6 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 > @@ -19,12 +19,84 @@ > #include > #include > > +/* > + * Hard coded to the first device to support sensor fifo. The EC has a 2048 > + * byte fifo and will trigger an interrupt when fifo is 2/3 full. > + */ > +#define CROS_EC_FIFO_SIZE (2048 * 2 / 3) > + > static char *cros_ec_loc[] = { > [MOTIONSENSE_LOC_BASE] = "base", > [MOTIONSENSE_LOC_LID] = "lid", > [MOTIONSENSE_LOC_MAX] = "unknown", > }; > > +static void get_default_min_max_freq_and_fifo_size(enum motionsensor_type type, > + u32 *min_freq, > + u32 *max_freq, > + u32 *max_fifo_events) > +{ > + /* we don't know fifo size, set to size previously used by sensor HAL */ > + *max_fifo_events = CROS_EC_FIFO_SIZE; > + > + 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: > + *max_fifo_events = 0; > + *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) > +{ > + struct { > + struct cros_ec_command msg; > + union { > + struct ec_params_get_cmd_versions params; > + struct ec_response_get_cmd_versions resp; > + }; > + } __packed buf; > + struct ec_params_get_cmd_versions *params = &buf.params; > + struct ec_response_get_cmd_versions *resp = &buf.resp; > + struct cros_ec_command *msg = &buf.msg; > + int ret; > + > + memset(&buf, 0, sizeof(buf)); > + msg->command = EC_CMD_GET_CMD_VERSIONS + cmd_offset; > + msg->insize = sizeof(*resp); > + msg->outsize = sizeof(*params); > + params->cmd = cmd; > + ret = cros_ec_cmd_xfer_status(ec_dev, msg); > + if (ret >= 0) { > + if (msg->result == EC_RES_SUCCESS) > + *mask = resp->version_mask; > + else > + *mask = 0; > + } > + return ret; > +} > + > int cros_ec_sensors_core_init(struct platform_device *pdev, > struct iio_dev *indio_dev, > bool physical_device) > @@ -33,6 +105,8 @@ int cros_ec_sensors_core_init(struct platform_device *pdev, > struct cros_ec_sensors_core_state *state = iio_priv(indio_dev); > struct cros_ec_dev *ec = dev_get_drvdata(pdev->dev.parent); > struct cros_ec_sensor_platform *sensor_platform = dev_get_platdata(dev); > + u32 ver_mask; > + int ret; > > platform_set_drvdata(pdev, indio_dev); > > @@ -47,8 +121,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); > > @@ -66,6 +148,20 @@ int cros_ec_sensors_core_init(struct platform_device *pdev, > } > state->type = state->resp->info.type; > state->loc = state->resp->info.location; > + if (state->msg->version < 3) { > + get_default_min_max_freq_and_fifo_size( > + state->resp->info.type, > + &state->min_freq, > + &state->max_freq, > + &state->fifo_max_event_count); > + } else { > + state->min_freq = > + state->resp->info_3.min_frequency; > + state->max_freq = > + state->resp->info_3.max_frequency; > + state->fifo_max_event_count = > + state->resp->info_3.fifo_max_event_count; > + } > } > > return 0; > diff --git a/include/linux/iio/common/cros_ec_sensors_core.h b/include/linux/iio/common/cros_ec_sensors_core.h > index ce16445411ac..4742a9637a85 100644 > --- a/include/linux/iio/common/cros_ec_sensors_core.h > +++ b/include/linux/iio/common/cros_ec_sensors_core.h > @@ -78,6 +78,13 @@ struct cros_ec_sensors_core_state { > unsigned long scan_mask, s16 *data); > > int curr_sampl_freq; > + > + /* Min and Max Sampling Frequency in mHz */ > + u32 min_freq; > + u32 max_freq; > + > + /* event fifo size represented in number of events */ > + u32 fifo_max_event_count; > }; > > /** > diff --git a/include/linux/mfd/cros_ec_commands.h b/include/linux/mfd/cros_ec_commands.h > index dcec96f01879..27d71cbf22f1 100644 > --- a/include/linux/mfd/cros_ec_commands.h > +++ b/include/linux/mfd/cros_ec_commands.h > @@ -1744,6 +1744,27 @@ struct ec_response_motion_sense { > uint8_t chip; > } info; > > + /* Used for MOTIONSENSE_CMD_INFO version 3 */ > + struct __ec_todo_unpacked { > + /* Should be element of enum motionsensor_type. */ > + uint8_t type; > + > + /* Should be element of enum motionsensor_location. */ > + uint8_t location; > + > + /* Should be element of enum motionsensor_chip. */ > + uint8_t chip; > + > + /* Minimum sensor sampling frequency */ > + uint32_t min_frequency; > + > + /* Maximum sensor sampling frequency */ > + uint32_t max_frequency; > + > + /* Max number of sensor events that could be in fifo */ > + uint32_t fifo_max_event_count; > + } info_3; > + > /* Used for MOTIONSENSE_CMD_DATA */ > struct ec_response_motion_sensor_data data; > > -- > 2.20.1 >