Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp3523631ybi; Tue, 18 Jun 2019 02:08:37 -0700 (PDT) X-Google-Smtp-Source: APXvYqwiENb5iTmuziJ62sZ7b2PsPRQIA2djOdVJNl2PwwwplHO3j7PRF9QJH6Y6KgH1bOJqdXB+ X-Received: by 2002:a17:90a:258b:: with SMTP id k11mr3812555pje.110.1560848917106; Tue, 18 Jun 2019 02:08:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560848917; cv=none; d=google.com; s=arc-20160816; b=WHIAwJQJ5PLjTwJLJwBi/aTdtouf9u3J5PhPqEp43nkmHpLqZKfb+3rVNXMFvaFtyw yPxrSCtl1qoZCGXHWKAw86mWRbJJ427XYe+hLeQ6whVsdn8lx6tzf44EFx5dIM08AsXd mzrQv3iX+yWPgePkvk5/Ki+qNN96Db7ypGixDHvSnwj82dIKwYRpjB/+hH1MpCR25WoP DDzzowimsrSUcVcDCspKXkITNGnAI/fPiETLmsh+FxZmJZE1iIDaq+OROAHRJD4d/foM yyiDdbLlAh1qpSAXSevEBjvHc2fQ5XUeyvm2j+sQwQbgCknUx2iUHmUUiIRwoYx/at5K YMHA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:to:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:from; bh=AuhRNUvNklBz9mF7GRplEaLnBg+UgdhNwErxXT/jJuM=; b=l957Q2gFxsmS3wq9LELcfBldv3kf/aRJVpgkeKtblrh1mnIDkw/+5UR05ouRaMIe7l Mu9and+9TT+2lThmMarCMJNcfYXs/ng+Fnt7khqWKYRYh1DBCUth2k9p52HDDBLNyvED gOp4lMdbofWPEogEHDw8baWnuJbTIn3fDG/b0SqDvGk/ZUscEa30AeFfmwgIpqnXcRKj BEp5btQNr4WMBLQWOi2C7QvJyaj2KthWcbgFhDmA1UN2t4yKKo9uLk/FaEf7AaOI+Lda WDquLwlx2nF2Vz1x5QgoaXuI58qNYL3QmCI0m6BSYMwEcCO61ihDGE5D5B8V1vv1WbAx tBaQ== 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 n9si12337415pff.14.2019.06.18.02.08.17; Tue, 18 Jun 2019 02:08:37 -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 S1729371AbfFRJHb (ORCPT + 99 others); Tue, 18 Jun 2019 05:07:31 -0400 Received: from bhuna.collabora.co.uk ([46.235.227.227]:60046 "EHLO bhuna.collabora.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728965AbfFRJHa (ORCPT ); Tue, 18 Jun 2019 05:07:30 -0400 Received: from laptop.home (unknown [IPv6:2a01:cb19:8ad6:900:42dd:dd1c:19ee:7c60]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: aragua) by bhuna.collabora.co.uk (Postfix) with ESMTPSA id AEB3A285312; Tue, 18 Jun 2019 10:07:28 +0100 (BST) From: Fabien Lahoudere Cc: kernel@collabora.com, Fabien Lahoudere , Jonathan Cameron , Hartmut Knaack , Lars-Peter Clausen , Peter Meerwald-Stadler , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 7/8] iio: common: cros_ec_sensors: add sysfs attribute for frequencies Date: Tue, 18 Jun 2019 11:06:38 +0200 Message-Id: X-Mailer: git-send-email 2.19.2 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit To: unlisted-recipients:; (no To-header on input) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Embedded controller return minimum and maximum frequencies, unfortunately we have no way to know the step for all available frequencies. Even if not complete, we can return a list of known values using the standard read_avail callback (IIO_CHAN_INFO_SAMP_FREQ) to provide them to userland. Now cros_ec_* sensors provides frequencies values in sysfs like this: "0 min max". 0 is always true to disable the sensor. Signed-off-by: Fabien Lahoudere --- .../cros_ec_sensors/cros_ec_sensors_core.c | 22 +++++++++++++++++++ .../linux/iio/common/cros_ec_sensors_core.h | 4 +++- 2 files changed, 25 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 2ce077b576a4..8df82b675752 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 @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -86,6 +87,26 @@ static int cros_ec_get_host_cmd_version_mask(struct cros_ec_device *ec_dev, return ret; } +static int cros_ec_read_avail(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, + const int **vals, + int *type, + int *length, + long mask) +{ + struct cros_ec_sensors_core_state *state = iio_priv(indio_dev); + + switch (mask) { + case IIO_CHAN_INFO_SAMP_FREQ: + *length = 3; + *vals = (const int *)&state->frequency_range; + *type = IIO_VAL_INT; + return IIO_AVAIL_LIST; + } + + return -EINVAL; +} + int cros_ec_sensors_core_init(struct platform_device *pdev, int num_channels, bool physical_device) @@ -161,6 +182,7 @@ int cros_ec_sensors_core_init(struct platform_device *pdev, } } + state->info.read_avail = cros_ec_read_avail; indio_dev->info = &state->info; /* Timestamp channel */ diff --git a/include/linux/iio/common/cros_ec_sensors_core.h b/include/linux/iio/common/cros_ec_sensors_core.h index 89937ad242ef..5fa9ba5332e0 100644 --- a/include/linux/iio/common/cros_ec_sensors_core.h +++ b/include/linux/iio/common/cros_ec_sensors_core.h @@ -140,7 +140,9 @@ int cros_ec_sensors_core_register(struct platform_device *pdev, channel[idx].scan_type.shift = 0;\ channel[idx].scan_index = idx;\ channel[idx].ext_info = cros_ec_sensors_ext_info;\ - channel[idx].scan_type.sign = 'u'; + channel[idx].scan_type.sign = 'u';\ + channel[idx].info_mask_shared_by_all_available = \ + BIT(IIO_CHAN_INFO_SAMP_FREQ); /** * cros_ec_motion_send_host_cmd() - send motion sense host command -- 2.20.1