From nobody Wed Nov 27 02:40:06 2024 Received: from mail-wm1-f44.google.com (mail-wm1-f44.google.com [209.85.128.44]) (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 F3CC81D5AB4 for ; Tue, 15 Oct 2024 09:09:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728983352; cv=none; b=t/08V9VY8MZHzMVtbpIGFR7F4jYYOv7wKlLWoceNeOpUqfT0pMRXVbro6nHi7ZXv7A69CCv3sAtKd43h4sW4I4beuD0dJTeQSuiFW6/Mgm0kug58ntkXuI4Y5slE5QqqO0fcvFuqbwjyt1IvG2SXyNsiwFCGtKCb3WBRAYdELPU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728983352; c=relaxed/simple; bh=o62uOnLdet39sGOU8s7LXAinW57s1Px5F5MzWy4QaUo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=MYSRNJ9etbmmBPU+f+e+g/7uvT90n5vuCEVv0eXkTFMqYYGt90XrGCGK5S3VYIDYIWNiMdXuJR/fGvpbVRLc40PpFqcxSthItTvnNuGlgCz8y4EUzLOTXtawICO87bl+J2Zt13bgjWG+vMw3giqNhx97AQugTRNKF/b7Fn9t6wQ= 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.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b=TwT9OVU+; arc=none smtp.client-ip=209.85.128.44 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.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b="TwT9OVU+" Received: by mail-wm1-f44.google.com with SMTP id 5b1f17b1804b1-430ee5c9570so60280075e9.3 for ; Tue, 15 Oct 2024 02:09:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1728983348; x=1729588148; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=sTy6VNLKeEKKTg69S3uNulsgrGlXdqfWHluaJ2NZUNs=; b=TwT9OVU+6mFxf4V+J65VJ4T2lg07misEpxnK53KwbDdZTr4x4AxiGTYKON64Bcmzh0 ikUQzPwOp3ZSL5+FGjEGqsQx2UjAmZYXeecSTW7dzt0vM0ZsbzE8aPCVAZhkcxlJpP30 NYWQpCmy2csXBuNPGNq2bvbkGTvXQmGg+F0dhr/nmc917yrBiuVlsqhlQSZuL6QVj71X hm25L3XKTX4pFQ9JCNJf5FFOuMxX1DfaW3lZPQOmNKYdU+M6pALdq9KR+cngbJWv3Xzn rRLjYy2L0m+XwPEoEnobEVwFZw+V0F66NTubBWf6mMXhXPveGjoKuQtNXifcAzXNidqg elfw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728983348; x=1729588148; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=sTy6VNLKeEKKTg69S3uNulsgrGlXdqfWHluaJ2NZUNs=; b=w7k3Q93LSbZ05caVyrzpGQl3Gu1wGIdBtVbFgcuEyo/24eDr+uN3EfBnMLexWZtwo8 wjvSNb/kdhOrfoukUCmLa6pPwIK64F97w+QEidFCvH5XA3RlPzJ78mf/4gwxm8cU7J7R t0jTMQvvYjCFXdM+ti6+S1RscrGAXzmkQm+GyfYDesQvyzTcnsq7OW32G+nR46XUp748 iKSybiAvlaIcEpzxkSsaCBEDjsHQ3J9jqG0GsHfX4lVKdTlIx7cPoU2O0FtWx/3F2d2s vCvBTbxx4kKHqv+lif+h2tJMzODrMcmUdFhv4bPT0BEkLsOSQdPb5w6eNeeFSHLNVxpg vFbg== X-Forwarded-Encrypted: i=1; AJvYcCVGapgnBDJRs1BXXGZVXbUDApI9QbvU/VKQBkrT8ZKyZ2Hc9Q0j20lrE4upAI1HAzjKhdZDRpqH0Oc4GqE=@vger.kernel.org X-Gm-Message-State: AOJu0YzAVTIqTpp5KnfqaziNXPGWdX7ohysncZzVxXlnrDcB6y57zm0f hfe033qV7LbwXdXneL/qzcy3ebS41E+c1hYcOd9zu4K9eyvOD3nejsNRT7JaKyY= X-Google-Smtp-Source: AGHT+IF1h+oXQTPOArXM1QcDAmgctLATg+guTpS56FPH/LhpgaycB2RtXYhpBTIaJ3MVVN/32EmSvA== X-Received: by 2002:a05:600c:1c9c:b0:42c:a8cb:6a5a with SMTP id 5b1f17b1804b1-431255df67amr113061465e9.15.1728983348183; Tue, 15 Oct 2024 02:09:08 -0700 (PDT) Received: from [192.168.1.64] (2a02-842a-d52e-6101-6fd0-06c4-5d68-f0a5.rev.sfr.net. [2a02:842a:d52e:6101:6fd0:6c4:5d68:f0a5]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-37d7fc123dasm1012882f8f.94.2024.10.15.02.09.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Oct 2024 02:09:07 -0700 (PDT) From: Julien Stephan Date: Tue, 15 Oct 2024 11:09:07 +0200 Subject: [PATCH RFC 2/4] iio: adc: ad7380: fix oversampling formula 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: quoted-printable Message-Id: <20241015-ad7380-add-adaq4380-4-support-v1-2-d2e1a95fb248@baylibre.com> References: <20241015-ad7380-add-adaq4380-4-support-v1-0-d2e1a95fb248@baylibre.com> In-Reply-To: <20241015-ad7380-add-adaq4380-4-support-v1-0-d2e1a95fb248@baylibre.com> To: Lars-Peter Clausen , Michael Hennerich , =?utf-8?q?Nuno_S=C3=A1?= , David Lechner , Jonathan Cameron , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Jonathan Corbet Cc: linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, Julien Stephan X-Mailer: b4 0.14.1 The formula in the datasheet for oversampling time conversion seems to be valid when device is at full speed using the maximum number of SDO lines. The driver currently support only 1 SDO line. The formula will produce larger delays than what is currently set, but some devices actually require it. Signed-off-by: Julien Stephan --- drivers/iio/adc/ad7380.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/drivers/iio/adc/ad7380.c b/drivers/iio/adc/ad7380.c index e9784769baa9..15ca85c70ebd 100644 --- a/drivers/iio/adc/ad7380.c +++ b/drivers/iio/adc/ad7380.c @@ -77,6 +77,12 @@ #define T_CONVERT_X_NS 500 /* xth conversion start time (oversampling) */ #define T_POWERUP_MS 5 /* Power up */ =20 +/* + * AD738x support several SDO lines to increase throughput, but driver cur= rently + * supports only 1 SDO line (standard SPI transaction) + */ +#define AD7380_NUM_SDO_LINES 1 + struct ad7380_timing_specs { const unsigned int t_csh_ns; /* CS minimum high time */ }; @@ -649,7 +655,8 @@ static int ad7380_set_ch(struct ad7380_state *st, unsig= ned int ch) =20 if (st->oversampling_ratio > 1) xfer.delay.value =3D T_CONVERT_0_NS + - T_CONVERT_X_NS * (st->oversampling_ratio - 1); + T_CONVERT_X_NS * (st->oversampling_ratio - 1) * + st->chip_info->num_simult_channels / AD7380_NUM_SDO_LINES; =20 return spi_sync_transfer(st->spi, &xfer, 1); } @@ -667,12 +674,13 @@ static void ad7380_update_xfers(struct ad7380_state *= st, =20 /* * In the case of oversampling, conversion time is higher than in normal - * mode. Technically T_CONVERT_X_NS is lower for some chips, but we use - * the maximum value for simplicity for now. + * mode: t_convert =3D T_CONVERT_0_NS + T_CONVERT_X_NS*(x - 1)*num_channe= l/number_of_sdo_lines + * where x is the oversampling ratio */ if (st->oversampling_ratio > 1) t_convert =3D T_CONVERT_0_NS + T_CONVERT_X_NS * - (st->oversampling_ratio - 1); + (st->oversampling_ratio - 1) * + st->chip_info->num_simult_channels / AD7380_NUM_SDO_LINES; =20 if (st->seq) { xfer[0].delay.value =3D xfer[1].delay.value =3D t_convert; @@ -1021,7 +1029,8 @@ static int ad7380_init(struct ad7380_state *st, bool = external_ref_en) /* SPI 1-wire mode */ return regmap_update_bits(st->regmap, AD7380_REG_ADDR_CONFIG2, AD7380_CONFIG2_SDO, - FIELD_PREP(AD7380_CONFIG2_SDO, 1)); + FIELD_PREP(AD7380_CONFIG2_SDO, + AD7380_NUM_SDO_LINES)); } =20 static int ad7380_probe(struct spi_device *spi) --=20 2.46.0