Received: by 2002:a05:6500:1b8f:b0:1fa:5c73:8e2d with SMTP id df15csp1247977lqb; Thu, 30 May 2024 05:09:11 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWQgNPqF7OssI2/f5dhbqULT3d8hW2EOgqaDk4f9O0alGwF/jMD6JZwSO6LWdTWzdYVkE/iU5f2JHbJiM6xm/xBefC4SOxA1E8/OSvB2A== X-Google-Smtp-Source: AGHT+IEAJfCDnhFlBDdlK4igxRe69STfz/GOnzvfHMWlpUS5hRAOiqZBKeJ+bCb9yrsXfC5ldIch X-Received: by 2002:a05:6122:1d90:b0:4e4:e90f:6749 with SMTP id 71dfb90a1353d-4eaf2426683mr2295702e0c.10.1717070950886; Thu, 30 May 2024 05:09:10 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717070950; cv=pass; d=google.com; s=arc-20160816; b=taxwEbIlvd7CtGcfY1x2ceDGq0fNnG9Ss3JaCbD7X0VXA7OX94+uT1PcAI1eZjzgW2 G5m99cTmTsngWMoZT/BiQFXIoqgPb1EdGh3Mh+54E6lfheWQJAwvWfYPTbuQ1I7lPYdB udQftOAbS/qunyjerssNgS4PCQGy/vkrCYcwSSm2AWNSojEMG0mBHzmn+M7ereZKrdgR kv44qwBMYILlE6Rn4+KRZccojLScfe7P4KdwCrbTdEwo8jU9QCHN094Nzi7pD9k4yQoQ TUl9gvs9eGZkcL0giAsYGZJfTOPU7rH8DnKlgZ7SWcPdWXnt1AZoWJI95N4xXxDvvYAy jKwg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=reply-to:cc:to:in-reply-to:references:message-id :content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:subject:date:from:dkim-signature; bh=Eyj81Qe/D+hlUYJ9l/XVK75Gk8yI6eaKEggct/cCrvQ=; fh=+0JxBwAIxgXrPbgpITLGafFl+qo+GEpLisyPcty2UQ8=; b=TisHHQqs30JR5QRmDNXVtTzfd01qsM9UpfVhEfxVJH65Ff7NZXd9Yg9Tyz+Gowhdkj THYRGgbyFt4l6vRuWm2r/Q63jIcs4BOaF+Ormz0+R/Fz/5FksULiYBiePEF1gxub9wCV 2yQwTmAw24Bh5C+KtYbXF3bYBADQLvi41h80rZE+lo1arwkh+XgccjNxM3LnTgzqj96r HdvDgCvEJb3h0fGQJ3uNmpusS3yycQoSsw7DIHv7tCdkx/qiTvbGTXgRWJDPpTFTk76D 3Ub0oWarxHttsBfPu81RlVF1baWoZuBEsGDztaA2QuQLgZ7MuO/s8S7985EHfA/aw7+H z6BA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Ik3hzkB+; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-195343-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-195343-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id ada2fe7eead31-48a3a34e4e1si196615137.469.2024.05.30.05.09.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 May 2024 05:09:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-195343-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Ik3hzkB+; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-195343-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-195343-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 9332A1C231A0 for ; Thu, 30 May 2024 12:09:10 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 94FF91C68A3; Thu, 30 May 2024 12:08:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Ik3hzkB+" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 78B94183A84; Thu, 30 May 2024 12:08:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717070884; cv=none; b=joYqLWpmJ4TtRvjIUdNvmQ2KnLEC83A65v8dB9YS0s5ZQorZK0Y5PJ01yvrInGGpyIK31YhAZbzKEgmlIy9N3JzD/abQ7JKk2vNBH9d3j9mIOwjEE0lf9IT1BuNKk3X7vRXhWASsqBsDXIaoMhOBUyL+YfkNZO+lG8NQ0fvqq/k= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717070884; c=relaxed/simple; bh=NGupSVFAf3w4i+B0v6O8ZHgy6jsWt10FDsN0sCp/Jv0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=XEN4YzYyK8kacxtIPLfemilqwiFNxed6r5l3GQxyc40yofwz6hP8HC1o/LgAYlYMhhvHCSHDE4fWENhTRMiaFsYsLafPZ6Rn6VxrpYWF93yV4i/oW7E8J2cKYwqiJaAKYx+Jc6Vi4HFv0AwtjONJziV7I6ToOGHq9LuDSvkMoWw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Ik3hzkB+; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPS id 25E15C4AF0A; Thu, 30 May 2024 12:08:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1717070884; bh=NGupSVFAf3w4i+B0v6O8ZHgy6jsWt10FDsN0sCp/Jv0=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=Ik3hzkB+9mYBamTB93UN+zjnXx+a/wgxzF7Mm8b9vQBS+pc4Me5N8QrLbcsnoceho vrrPfHMUMDgfiPhbxVOQ+kKO/fwtPlojRlErrhCU1reQfXg9RwlDtgoLh7d7tVtfm1 vIM9xZCPVrr2LhbZPXMmOMcvFBYOWdgemwTKLqU0wsb6W11QAaLLM3dfWHic6v/eGd uQmWMKhhAXCm5R7a4cfFcdy++ahXmcOBu5QtFIk0m2FN3la/vmTxzAL81+K4VsW3c4 m/sGa8ajWbjfufjofU+CAFHcTLxyjMnYrMRX6g39POlhaQ+B0WWp2GUuO2aZuBpPha tgeUXAPuh6hcQ== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1CEF3C25B74; Thu, 30 May 2024 12:08:04 +0000 (UTC) From: Dumitru Ceclan via B4 Relay Date: Thu, 30 May 2024 15:07:53 +0300 Subject: [PATCH v3 5/5] iio: adc: ad7173: Fix sampling frequency setting Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20240530-ad7173-fixes-v3-5-b85f33079e18@analog.com> References: <20240530-ad7173-fixes-v3-0-b85f33079e18@analog.com> In-Reply-To: <20240530-ad7173-fixes-v3-0-b85f33079e18@analog.com> To: Lars-Peter Clausen , Jonathan Cameron Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, Dumitru Ceclan , Dumitru Ceclan X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1717070881; l=2969; i=dumitru.ceclan@analog.com; s=20240313; h=from:subject:message-id; bh=SBPCEDIHiCkBTrkchaltcj60L2/HmJ7NW2rt8H7uZxM=; b=1yI8EuMNC1kGPCv+tv4qpgt9g1y7ShB+N4rgprlmp+0NraSAwqk4cxA7tfpVxGYlbztHEub0w 3gVkgAXonMJAdtMh4xcWYt0oz0VLNdOjvpi2DvO9z3NmxYa60LMCN+Z X-Developer-Key: i=dumitru.ceclan@analog.com; a=ed25519; pk=HdqMlVyrcazwoiai7oN6ghU+Bj1pusGUFRl30jhS7Bo= X-Endpoint-Received: by B4 Relay for dumitru.ceclan@analog.com/20240313 with auth_id=140 X-Original-From: Dumitru Ceclan Reply-To: dumitru.ceclan@analog.com From: Dumitru Ceclan This patch fixes two issues regarding the sampling frequency setting: -The attribute was set as per device, not per channel. As such, when setting the sampling frequency, the configuration was always done for the slot 0, and the correct configuration was applied on the next channel configuration call by the LRU mechanism. -The LRU implementation does not take into account external settings of the slot registers. When setting the sampling frequency directly to a slot register in write_raw(), there is no guarantee that other channels were not also using that slot and now incorrectly retain their config as live. Set the sampling frequency attribute as separate in the channel templates. Do not set the sampling directly to the slot register in write_raw(), just mark the config as not live and let the LRU mechanism handle it. As the reg variable is no longer used, remove it. Fixes: 8eb903272f75 ("iio: adc: ad7173: add AD7173 driver") Signed-off-by: Dumitru Ceclan --- drivers/iio/adc/ad7173.c | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/drivers/iio/adc/ad7173.c b/drivers/iio/adc/ad7173.c index e66a137a76be..ebf248741b34 100644 --- a/drivers/iio/adc/ad7173.c +++ b/drivers/iio/adc/ad7173.c @@ -717,7 +717,7 @@ static int ad7173_write_raw(struct iio_dev *indio_dev, { struct ad7173_state *st = iio_priv(indio_dev); struct ad7173_channel_config *cfg; - unsigned int freq, i, reg; + unsigned int freq, i; int ret; ret = iio_device_claim_direct_mode(indio_dev); @@ -733,16 +733,7 @@ static int ad7173_write_raw(struct iio_dev *indio_dev, cfg = &st->channels[chan->address].cfg; cfg->odr = i; - - if (!cfg->live) - break; - - ret = ad_sd_read_reg(&st->sd, AD7173_REG_FILTER(cfg->cfg_slot), 2, ®); - if (ret) - break; - reg &= ~AD7173_FILTER_ODR0_MASK; - reg |= FIELD_PREP(AD7173_FILTER_ODR0_MASK, i); - ret = ad_sd_write_reg(&st->sd, AD7173_REG_FILTER(cfg->cfg_slot), 2, reg); + cfg->live = false; break; default: @@ -804,8 +795,7 @@ static const struct iio_chan_spec ad7173_channel_template = { .type = IIO_VOLTAGE, .indexed = 1, .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | - BIT(IIO_CHAN_INFO_SCALE), - .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ), + BIT(IIO_CHAN_INFO_SCALE) | BIT(IIO_CHAN_INFO_SAMP_FREQ), .scan_type = { .sign = 'u', .realbits = 24, @@ -819,8 +809,8 @@ static const struct iio_chan_spec ad7173_temp_iio_channel_template = { .channel = AD7173_AIN_TEMP_POS, .channel2 = AD7173_AIN_TEMP_NEG, .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | - BIT(IIO_CHAN_INFO_SCALE) | BIT(IIO_CHAN_INFO_OFFSET), - .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ), + BIT(IIO_CHAN_INFO_SCALE) | BIT(IIO_CHAN_INFO_OFFSET) | + BIT(IIO_CHAN_INFO_SAMP_FREQ), .scan_type = { .sign = 'u', .realbits = 24, -- 2.43.0