Received: by 2002:a25:f815:0:0:0:0:0 with SMTP id u21csp2226401ybd; Thu, 27 Jun 2019 08:49:43 -0700 (PDT) X-Google-Smtp-Source: APXvYqxe6+GzMLy5E+F4NnKZlSfdwQ59A4KvfJltykBSSmrP7NEBdBBaHolqbEZC9KgB1VTcSI3I X-Received: by 2002:a17:902:6a85:: with SMTP id n5mr5119802plk.73.1561650583225; Thu, 27 Jun 2019 08:49:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561650583; cv=none; d=google.com; s=arc-20160816; b=zmJ7Bq0kj27l1h0wzCqERbQesOtzkSeoP8Kdwab0poWAdbevxJTVa6dTzqUw5yKjjb An6y9dWVMUuqCHnE+lMM1MNDUQyMF6q5ERQjPfegP/PAqGYgDGig0vVvt741QegdC17d L5V5Vxv3d3fz5bTUe0ptVjQozmJuwvYFY9DqHixMi/91WlAHrOHmjUo8pofUBAIViZch AMaEXxofhtImGtR/bKbD95bNxy60yGbpoz2Q2gCw2FgwV9hnNhRV8ct4UqKdxxMnz1pU H3+sb1vEPZz0BgwjD59qSzJhCVhuXjxV/QWPq/FVMs2WCJuHVYT6aq+36u59xVM+mIJA A8mQ== 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 :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=mI5l033TLGDdBr6LA9JQ73iD6NXmwX07q8lnuSziBXI=; b=O5SweeOPTI95trBrlmrVjKN41DOYAWIA9NJRhHTt7dL/PvftQKUoQ9mjUa/sVzYegJ m3nLvQkceHLYlDmepgu+iVAjmPO6EigiCMs1/veyobJ4CD2QW17CMnGpyQ8VjUdNOZqC 5akVQZPCNXOPoc0ny9xMlpKhBAc16WGtR9lG6NDp0CEFDLLRd0vo826f+YpVtUqacczp 7uDdR1n5sGajj+/lMOq2LDEfq//H+Mmp3KKYqatQYLMucgAvPPlF3vaW2Nyr/WNGBtBB aAoyAo9KlP1wsSFMo4ElJur7QYa7kAg6Ds9EkvwE2ciFatC0T6eyJmAJEuIH65gytqjY xSWw== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=collabora.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y2si2339062pgh.524.2019.06.27.08.49.26; Thu, 27 Jun 2019 08:49:43 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726487AbfF0PtC (ORCPT + 99 others); Thu, 27 Jun 2019 11:49:02 -0400 Received: from bhuna.collabora.co.uk ([46.235.227.227]:47070 "EHLO bhuna.collabora.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726187AbfF0PtC (ORCPT ); Thu, 27 Jun 2019 11:49:02 -0400 Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: eballetbo) with ESMTPSA id 9D6C2285135 Subject: Re: [PATCH 2/2] iio: common: cros_ec_sensors: set default frequencies To: Fabien Lahoudere Cc: kernel@collabora.com, Nick Vaccaro , Jonathan Cameron , Hartmut Knaack , Lars-Peter Clausen , Peter Meerwald-Stadler , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org References: <7d3972d1200065fe6e98a310e66f53a7ed12e281.1561642224.git.fabien.lahoudere@collabora.com> From: Enric Balletbo i Serra Message-ID: <6ca7ee49-51f9-a65f-5f71-0eac04ee9434@collabora.com> Date: Thu, 27 Jun 2019 17:48:57 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.7.1 MIME-Version: 1.0 In-Reply-To: <7d3972d1200065fe6e98a310e66f53a7ed12e281.1561642224.git.fabien.lahoudere@collabora.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-GB Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Fabien, On 27/6/19 16:04, Fabien Lahoudere wrote: > Version 3 of the EC protocol provides min and max frequencies for EC sensors. > Default frequencies are provided for earlier protocol. > This patch should really go together with a respin of your previous patchset to 'Expose cros_ec_sensors frequency range via iio sysfs' [1] [1] https://www.spinics.net/lists/linux-iio/msg44963.html > Signed-off-by: Fabien Lahoudere > Signed-off-by: Nick Vaccaro > --- > .../cros_ec_sensors/cros_ec_sensors_core.c | 44 +++++++++++++++++++ > .../linux/iio/common/cros_ec_sensors_core.h | 3 ++ > 2 files changed, 47 insertions(+) > > 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 2e0f97448e64..72f56d54cccd 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 > @@ -50,6 +50,37 @@ static int cros_ec_get_host_cmd_version_mask(struct cros_ec_device *ec_dev, > return ret; > } > > +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; > + } > +} > + > int cros_ec_sensors_core_init(struct platform_device *pdev, > struct iio_dev *indio_dev, > bool physical_device) > @@ -100,6 +131,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->frequencies[0] = 0; > + if (state->msg->version < 3) { > + get_default_min_max_freq(state->resp->info.type, > + &state->frequencies[1], > + &state->frequencies[2]); > + } else { > + state->frequencies[1] = > + state->resp->info_3.min_frequency; > + state->frequencies[2] = > + state->resp->info_3.max_frequency; > + } > } > > 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 0c636b9fe8d7..94c87da22c04 100644 > --- a/include/linux/iio/common/cros_ec_sensors_core.h > +++ b/include/linux/iio/common/cros_ec_sensors_core.h > @@ -70,6 +70,9 @@ struct cros_ec_sensors_core_state { > unsigned long scan_mask, s16 *data); > > int curr_sampl_freq; > + > + /* Disable, Min and Max Sampling Frequency in mHz */ > + int frequencies[3]; > }; > > /** >