Received: by 2002:a05:6a10:2785:0:0:0:0 with SMTP id ia5csp1307914pxb; Sat, 9 Jan 2021 15:15:30 -0800 (PST) X-Google-Smtp-Source: ABdhPJyNaboOTTCToDNkNjMqmr4b9h+5m6W7LKQURy+E5k1ykvCw73YiiqmIObsatwfGwPcC5h+Z X-Received: by 2002:a05:6402:128d:: with SMTP id w13mr9405914edv.56.1610234130088; Sat, 09 Jan 2021 15:15:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610234130; cv=none; d=google.com; s=arc-20160816; b=Cv3p+0g2vt+nj1/5PoTSje5deq79SqTUkwnBiMx40v88JvO8rBJXe0F9OAa0/3YNnT 6kGOTpWo5jQijxveeom5FDujgbin8U/+cz+cun9T+kDr4daK2lBdFqlu/Xtq8Hbf/Qxp 7HxhTrH7E3XpPLTd+CNaMh3US1+NuqcJm+XP/7Glve/1592lm+fi5WsF2jXY3au/rpYt 3TpSphZvD6H8N8hGk1oMjjSd3/bG+iVY6d+OyK3xe3x5UOUnsxxRzsz+awwLdAZW8PjP 3Thpm8QeDE82aGpdk43kOHYBmXAoeOWLcl/gP6WCL6FrE5XNEGCCZA7w2oUE/FLc0+8T 3JPw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=aPfsdomTXm2sIXa6Lbi7GbgRl1BakkZdI+CG9PbBN9s=; b=or5b5hYGnNe2jBiC59crnXB1GIPDSBI9el/tFP3vuHimJ6ph0ayC2eW2EqIzKhCqAd HvN32y36TOPFsELbrF+YnOE385UjMSAZ5ZyttcApMXWfv2fKBoII0wiLBE9HAHzJ0th8 Iodzh9C898QC4ZTzAET89jn0tc2PljXovGiOcfgHZQCswfVK4wyieZi69QpPG7bgIk9O 9ya6x1d042hwEKz1Pd7MkwLmXxaO18g8wrZ2sYY9NsE73nmkCBdp1DDjmauSrxaKi3QP Jw4FwzhXNhhX9oUBGrR4ePnmYWwalwJfk6b9n8eJVXSmIJ8+PeU7sMRm4BvIhjYH1mSl S9lQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id de28si5068967edb.166.2021.01.09.15.15.05; Sat, 09 Jan 2021 15:15:30 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726495AbhAIXN0 (ORCPT + 99 others); Sat, 9 Jan 2021 18:13:26 -0500 Received: from relay8-d.mail.gandi.net ([217.70.183.201]:45993 "EHLO relay8-d.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726454AbhAIXNY (ORCPT ); Sat, 9 Jan 2021 18:13:24 -0500 X-Originating-IP: 86.202.109.140 Received: from localhost (lfbn-lyo-1-13-140.w86-202.abo.wanadoo.fr [86.202.109.140]) (Authenticated sender: alexandre.belloni@bootlin.com) by relay8-d.mail.gandi.net (Postfix) with ESMTPSA id C74031BF204; Sat, 9 Jan 2021 23:12:41 +0000 (UTC) From: Alexandre Belloni To: Jonathan Cameron Cc: Lars-Peter Clausen , Peter Meerwald-Stadler , linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Alexandre Belloni Subject: [PATCH v2 3/6] iio:pressure:ms5637: limit available sample frequencies Date: Sun, 10 Jan 2021 00:11:45 +0100 Message-Id: <20210109231148.1168104-4-alexandre.belloni@bootlin.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210109231148.1168104-1-alexandre.belloni@bootlin.com> References: <20210109231148.1168104-1-alexandre.belloni@bootlin.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Avoid exposing all the sampling frequencies for chip that only support a subset. Signed-off-by: Alexandre Belloni --- Changes in v2: -use sysfs_emit_at drivers/iio/pressure/ms5637.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/drivers/iio/pressure/ms5637.c b/drivers/iio/pressure/ms5637.c index fdd557ac71a3..0a6034342714 100644 --- a/drivers/iio/pressure/ms5637.c +++ b/drivers/iio/pressure/ms5637.c @@ -36,8 +36,19 @@ struct ms_tp_data { }; static const int ms5637_samp_freq[6] = { 960, 480, 240, 120, 60, 30 }; -/* String copy of the above const for readability purpose */ -static const char ms5637_show_samp_freq[] = "960 480 240 120 60 30"; + +static ssize_t ms5637_show_samp_freq(struct device *dev, struct device_attribute *attr, char *buf) +{ + struct iio_dev *indio_dev = dev_to_iio_dev(dev); + struct ms_tp_dev *dev_data = iio_priv(indio_dev); + int i, len = 0; + + for (i = 0; i <= dev_data->hw->max_res_index; i++) + len += sysfs_emit_at(buf, len, "%u ", ms5637_samp_freq[i]); + sysfs_emit_at(buf, len - 1, "\n"); + + return len; +} static int ms5637_read_raw(struct iio_dev *indio_dev, struct iio_chan_spec const *channel, int *val, @@ -114,10 +125,10 @@ static const struct iio_chan_spec ms5637_channels[] = { } }; -static IIO_CONST_ATTR_SAMP_FREQ_AVAIL(ms5637_show_samp_freq); +static IIO_DEV_ATTR_SAMP_FREQ_AVAIL(ms5637_show_samp_freq); static struct attribute *ms5637_attributes[] = { - &iio_const_attr_sampling_frequency_available.dev_attr.attr, + &iio_dev_attr_sampling_frequency_available.dev_attr.attr, NULL, }; -- 2.29.2