Received: by 2002:a25:f815:0:0:0:0:0 with SMTP id u21csp283240ybd; Sat, 22 Jun 2019 03:15:50 -0700 (PDT) X-Google-Smtp-Source: APXvYqzZyeqKE9xZIqKha2mfLuyYj1pbMga2kt9NyouDLahN/0CRRujy0zjMAfY0jznqgOAVG/U7 X-Received: by 2002:a63:4419:: with SMTP id r25mr23688187pga.247.1561198550737; Sat, 22 Jun 2019 03:15:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561198550; cv=none; d=google.com; s=arc-20160816; b=dXOaU5QPD+RUu12g9ec+690ykcCMRjHduT53I4tCFvA5pdwXwEJjpdk9dkz4TylXGc XlJKFl4/zu9liGrE2u3BWz69crIaHpkyBWpOykUYzpnoZ3iVYh2+G+ZdXQRUu8mwNSa8 /XSSYtmIg8yx5JHSbPsBHbD0NGXhWue/PoCevDiLlbFgHsPXQYDz0DCQl/96QgT0O9BY yzeXJFHCafuMFXal93botgjA1aVUwOGUeqoSAuhuHhqVh6NfurlAamq27LBbxqEWJwmE nZSSd1M7IDSrAVCLVT1128qHPOcIah84TTWiFc8hCc+w0zYFCuOiNQNY1Nt/+Of9iPTz IK6A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=Bxo6D2AuGKHP76q714OD66M0pjC6lR8LbZABV8R5kE4=; b=osgywLF+GxzuujM8ywpQUggE0f2xzt69KnCz8GIylhqrLu7YrR/9wB5k/kgNHems2C jOmfRcIWtZOUaD4YJzbOqiOMgmWEnC5qca7skDrq/Ika/8Bzi0cBARLf3Uy5Kj0Ox4v9 4AcephQLfIY9OBQ5Bbj0zTPDko8/b4tMcnTqiEvEXYk60JX4zystcxAi7QXTvnZSlwDz tf8AEPZGONKJ2Piq9rmMMlrBzXsoGcJFKaSzn/ai2ZYbABJ55p1LeqczmuMxf53tDOY2 poiPUzDz5hfo2UTQTUHJeziHGeSOq5jIwZTrTEVPG1Jdwf0TX30q37iwXiegqtMrX65P O1pg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=SnbLDfjZ; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c3si4802734pgh.340.2019.06.22.03.15.35; Sat, 22 Jun 2019 03:15:50 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=SnbLDfjZ; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726287AbfFVKPQ (ORCPT + 99 others); Sat, 22 Jun 2019 06:15:16 -0400 Received: from mail.kernel.org ([198.145.29.99]:34360 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726121AbfFVKPP (ORCPT ); Sat, 22 Jun 2019 06:15:15 -0400 Received: from archlinux (cpc149474-cmbg20-2-0-cust94.5-4.cable.virginm.net [82.4.196.95]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 1981020665; Sat, 22 Jun 2019 10:15:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1561198514; bh=PQzwQraMLL3vzAgVlf8Nc3bpSNwv9Dk/yJXFLls1GLE=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=SnbLDfjZux51t1km6mrW9B7ZOcMJsDz0jW79UOU9ZoMzl27NjD4L2WSLJQRn2JN3N YPyuwz64iNsTH0azH1d1xSHj13M2VLhYF7MaqwaGXgz1VwxavguDMXeamXbnaQyLVo DKofFvSDtLY8jldwcURnGpNDgzIBsEklo1iwdvPM= Date: Sat, 22 Jun 2019 11:15:09 +0100 From: Jonathan Cameron To: Fabien Lahoudere Cc: kernel@collabora.com, Nick Vaccaro , Hartmut Knaack , Lars-Peter Clausen , Peter Meerwald-Stadler , 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 Message-ID: <20190622111509.314d25bf@archlinux> In-Reply-To: References: X-Mailer: Claws Mail 3.17.3 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 18 Jun 2019 11:06:37 +0200 Fabien Lahoudere wrote: > Version 3 of the EC protocol provides min and max frequencies for EC sensors. > > Signed-off-by: Fabien Lahoudere > Signed-off-by: Nick Vaccaro 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]; > }; > > /**