From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ot1-f53.google.com (mail-ot1-f53.google.com [209.85.210.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B9F133112BD for ; Sat, 27 Jun 2026 22:31:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.53 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782599489; cv=none; b=Fnkkv1hufsLIXf7NA8Wyg6TWMcKWFaFEnnDixJ6iZjbpTbRuhdfzp3/NTofUTRipcJR/boK/dd/FtE8J8m1qWkFGgdaw6gauAXPZN4A8s8/xGuym6UjdZu1EwAvNbl3bdPwAFQLVgKclDFqYYt3+iWmZl5IBUzLYyt8fmvbRhv8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782599489; c=relaxed/simple; bh=tOP/ncqJR9tQ1Kpjwwjs1DsUnFQQsFsCKUquXTGz2FE=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=LoweAe3pWEHde86Jc1Uumw73AmT709cJBcZbiJi6eViOrKX/7GnCpqObWfaDsAogSaE2RQ6xMc/8PUcq7+aGlu/sDtFGDt90G0BAX9GxdZOx2XwEJUwaP/kWbDZ99XHW7H95Tqy70N3sPTeLd/IjnXpIheI1vKleRJGTQKKsynM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com; spf=pass smtp.mailfrom=baylibre.com; dkim=pass (2048-bit key) header.d=baylibre.com header.i=@baylibre.com header.b=LgYv+/Ym; arc=none smtp.client-ip=209.85.210.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=baylibre.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=baylibre.com header.i=@baylibre.com header.b="LgYv+/Ym" Received: by mail-ot1-f53.google.com with SMTP id 46e09a7af769-7e6b5737bb2so2423873a34.1 for ; Sat, 27 Jun 2026 15:31:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre.com; s=google; t=1782599487; x=1783204287; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=b/hsn5oXO1Y2F7PgZaWccBbIlkiaMD42rC1dxoRTlLw=; b=LgYv+/Ym15oHC//cSW2LfJNH1Ubfm3aUOwTB4okduiBf9SGpuKhaLgUz7Y36jtTkt+ ezbp8ZrLhbIr1ImStGlUe9Tv4a+w82A3uzBwz2oOj0dSkpZaYHyq9t6ADlF21DjuX7+Q FYB2mzPljP1wCnCtqZIURZU8zj0AdrLRsWX6v+8ormaR5zWwmaZAN+FLdxP+/UNfLivM 6DznYiwJTUX9+7/ntnRaB8p+HFaAScRWAB/lPM9SQiWQ9NIgrgj5NMwmX/6q/nyjeUeG eDILeng3rQg7kEOHCGWSB6iJeqdFJbYkNW+szDLyMsLRwbTTS/YlRSFAdZMCh1ARoO7G dzJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782599487; x=1783204287; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=b/hsn5oXO1Y2F7PgZaWccBbIlkiaMD42rC1dxoRTlLw=; b=Olr+Z+v3n28dOaC6NTGLdWOBSuUcruvsmt1xWLZ4ZOKvnYwJxaeUR9e0EpHgeSxRTn Djb6Y5zJvwhVIXVUly4GfwThGgNFBOuSm+0U3M9dCAG/fVQcW/2S9Jux53TfzpCVf0kV 4CmENOEwwQnar3WKRgDuz4LeubfhDtuUak6QeCRNjt7wCIODVa9j3I/Qffo9JLRZ9pv6 z+mjDzopt2IOTgYi/Gd9efcw0Apr4uxZ8aZ7KhrmB9/6PLMsanDvI1rN6YzwqDEgCePG UVT5umgwbdY8CFX1gXHSAgjmqAvzrBFq1djejptLclD1XR2DKNTq+O6vFatBgUpFIj28 KZ0Q== X-Forwarded-Encrypted: i=1; AFNElJ91SDr8YvXlcsp7Yw4T6e/JzBIeQ8Ln5Pxf/ytTiTOTpaw018kWDkCioCwsJIj2iJlRoLFbZGJHx/rd/9c=@vger.kernel.org X-Gm-Message-State: AOJu0Yx9N7HSoTz86cIASLpAhAYfvs+A0gKCQ13IMJ06axXNj4jc7U1s PZkEYAQUQk+trOrBRSnYw+Fyb/r5aPq8iEssdBQ9L+/mORwFRe7r/Ccfc7jlcW1fIoY= X-Gm-Gg: AfdE7cnKxapHozV9n4cRiMThdC8WZpfUC4Y3D/2pHNBbM02+sv2WYQ5naB9k4Y/wr9m AGUttjkzFAXqdWF+DeOfPb+uFJVaFz+o5Y4t9ZA0FbD6NW2ErmjiG3YwfhSTyZCfDTE2rzNs+lp FEW78sGiDgb1POKzBV4y+eZg/3YpCi1uTuLh3+B/eWnpPs/bA8nuFTUMeKkUAxXbGFbBMO7JMka XXx8BBcGYdumk1tTfdPwFLiIbNcPFvHtvuXB1JD98Fuw2wAHFZ9K3PanLaK0vEkoAfSjKdocFQN 3ju15ujmK+9+xRmTGpccXJZ8mC5Xa+2VAan7tY2kZi196UABLSF9oq7nowsbB1BCjtCIayNzl4E pL7UvJBjY2r+714x/CFgmOtp7EwNEyqLxw9Y9NHi8UElYY+DnW3HGDPDkkFqPsgHCMhCDLJO4Vv tvJ8ivDG/0pvE8hH/EowAuHp236GyZL1rHQpzy8bjcwIU5L4SFwq4O9PpDD2CBjNO3XcI9qFCkn g== X-Received: by 2002:a05:6830:6d52:b0:7e6:ef1d:4aeb with SMTP id 46e09a7af769-7e99c208aabmr10277232a34.15.1782599486759; Sat, 27 Jun 2026 15:31:26 -0700 (PDT) Received: from ?IPV6:2600:8803:e7e4:500:f242:ecd6:f61e:d764? ([2600:8803:e7e4:500:f242:ecd6:f61e:d764]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-7e9b292029dsm3805497a34.22.2026.06.27.15.31.25 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 27 Jun 2026 15:31:25 -0700 (PDT) Message-ID: <5e96801b-50dc-4752-8e00-1a80984ed997@baylibre.com> Date: Sat, 27 Jun 2026 17:31:24 -0500 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v4 1/3] iio: adc: Fix incorrect reading when datarate changed in single mode To: Jakub Szczudlo , linux-iio@vger.kernel.org Cc: andy@kernel.org, antoniu.miclaus@analog.com, conor+dt@kernel.org, devicetree@vger.kernel.org, duje@dujemihanovic.xyz, jic23@kernel.org, jishnu.prakash@oss.qualcomm.com, jorge.marques@analog.com, joshua.crofts1@gmail.com, krzk+dt@kernel.org, linusw@kernel.org, linux-kernel@vger.kernel.org, marcelo.schmitt@analog.com, mazziesaccount@gmail.com, mike.looijmans@topic.nl, nuno.sa@analog.com, robh@kernel.org, sakari.ailus@linux.intel.com, wens@kernel.org References: <20260622221550.374235-1-jakubszczudlo40@gmail.com> <20260622221550.374235-2-jakubszczudlo40@gmail.com> Content-Language: en-US From: David Lechner In-Reply-To: <20260622221550.374235-2-jakubszczudlo40@gmail.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 6/22/26 5:15 PM, Jakub Szczudlo wrote: > When device is suspended and it is in single mode then changing > datarate doesn't make it actual wait for new measurement, so to > be sure that read after change is correct functions that changes > datarate and gain will wait for new data. > > Fixes: 541880542f2b ("iio: adc: Add TI ADS1100 and ADS1000") > Signed-off-by: Jakub Szczudlo > --- > drivers/iio/adc/ti-ads1100.c | 74 ++++++++++++++++++++++++++++++++++-- > 1 file changed, 70 insertions(+), 4 deletions(-) > > diff --git a/drivers/iio/adc/ti-ads1100.c b/drivers/iio/adc/ti-ads1100.c > index 9fe8d54cce83..e3c801381434 100644 > --- a/drivers/iio/adc/ti-ads1100.c > +++ b/drivers/iio/adc/ti-ads1100.c > @@ -15,6 +15,7 @@ > #include > #include > #include > +#include > #include > #include > #include > @@ -43,6 +44,9 @@ > static const int ads1100_data_rate[] = { 128, 32, 16, 8 }; > static const int ads1100_data_rate_bits[] = { 12, 14, 15, 16 }; > > +/* Timeout based on the minimum sample rate of 8 SPS (7.5s) */ > +#define ADS1100_MAX_DRDY_TIMEOUT_US 7500000 > + > struct ads1100_data { > struct i2c_client *client; > struct regulator *reg_vdd; > @@ -123,10 +127,49 @@ static int ads1100_get_adc_result(struct ads1100_data *data, int chan, int *val) > return 0; > } > > +static bool ads1100_new_data_not_ready(struct ads1100_data *data) > +{ > + int ret; > + u8 buffer[3]; > + > + ret = i2c_master_recv(data->client, (char *)&buffer, sizeof(buffer)); Do we actually need the cast here? char * is like void * and should not need it. > + if (ret < 0) { > + dev_err(&data->client->dev, "I2C read fail: %d\n", ret); > + return true; > + } else if (ret < 3) { I don't think it is possible to return anything other than 3 or error. In other words, short read without error is not possible. > + dev_err(&data->client->dev, "Short I2C read\n"); > + return true; > + } > + > + return FIELD_GET(ADS1100_CFG_ST_BSY, buffer[2]); > +} > + > +static int ads1100_poll_data_ready(struct ads1100_data *data) > +{ > + int ret; > + u8 buffer[3]; > + bool data_ready; > + int datarate = ads1100_data_rate[FIELD_GET(ADS1100_DR_MASK, data->config)]; > + /* To be sure we wait 5 times more than datarate */ > + unsigned long wait_time = DIV_ROUND_CLOSEST(MICRO, 5 * datarate); This is a bit dense making it hard to read. Also, it's always helpful to include units in variable names. wait_time_us? data_rate_hz? > + > + /* To be sure that polled value will have value after config change */ > + ret = i2c_master_recv(data->client, (char *)&buffer, sizeof(buffer)); > + if (ret < 0) { > + dev_err(&data->client->dev, "I2C read fail: %d\n", ret); > + return ret; > + } > + > + return read_poll_timeout(ads1100_new_data_not_ready, data_ready, > + !data_ready, wait_time, > + ADS1100_MAX_DRDY_TIMEOUT_US, false, data); > +} > +