From nobody Thu Feb 12 00:24:32 2026 Received: from mail-lj1-f178.google.com (mail-lj1-f178.google.com [209.85.208.178]) (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 AE95E18EFC3 for ; Tue, 18 Jun 2024 13:45:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718718310; cv=none; b=VZyFjwN/NqU6DbbF7AVHBL9aND4RlM4snapXgJjFUWPmnNdsORQjjsb2b3W3CaGYrBIF3fk2QoDqCxbJPSo7cCoebzuKZUgnkLyWEvjk2++kVfd6kaxxQGotrh1wsnobJHAbdu+XCmeRE//5Z+HWcHTutKBjlvRWBo+TIBnLYU0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718718310; c=relaxed/simple; bh=ae4pwjFhUlQcrVR7mQTgRv94AhEmxr16sF6IEJpjbGg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To:Cc; b=SzKNNOhMOrBD8Yt1XI5Xbnhl65JhmPDfZ6Gv3eD0bY4bTTG/J3ATNrOE4lPdPLjl2FBEgTbf53TgA+EZzTTxDOkz60h7BDAiMatvkXeTXEYo9oJvJtc+OSAroIoVmNn2rJFlTPFL51vBk8x711JnE4mSbh7KmycxZLV7qLWBM/E= 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=kTMKmF/u; arc=none smtp.client-ip=209.85.208.178 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="kTMKmF/u" Received: by mail-lj1-f178.google.com with SMTP id 38308e7fff4ca-2e724bc46c4so61237751fa.2 for ; Tue, 18 Jun 2024 06:45:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1718718307; x=1719323107; darn=vger.kernel.org; h=cc:to:message-id:content-transfer-encoding:mime-version:subject :date:from:from:to:cc:subject:date:message-id:reply-to; bh=LmejdlmDlKHI06rCiq7kfLWivv1c0iup9shJzGhfZyM=; b=kTMKmF/unm1iy5Dc+sTket50eoAUbQ/ssmcEE+Pfr73E8I22m+cTxJ9eGdR1QTfn6e OQrRffwW9wOXsAFZdEtqQzOEWAGV/M+u+4I19gQ0XU3BOcVmvACppYDrRxBaBOvOjLYp cV+s/ytz1HbPodug8aq7+nLJ/aDspJM8OkFJ6iMdEKF6Z67kH/B34Ktqh+it5b6FL0V+ QqtvokY5yes0K8xvVC2LRmHBG1FxdJw5LJb+85CPOIKtjbiXfq9U/1Y21yU6QqZfkYXZ kboHV5/jfkPhVMZaiFSoyt/eZ/1Z5QoZv9B5PtH6QBWlu7ClMhewTuwGQjXc1eYGokG5 9DGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718718307; x=1719323107; h=cc:to:message-id:content-transfer-encoding:mime-version:subject :date:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=LmejdlmDlKHI06rCiq7kfLWivv1c0iup9shJzGhfZyM=; b=EY436yKDOFSIv3JUf9fsvO8qFodhGhUNzZWwrVnLHqaZ2liZl1D8vRR7UneQtRyqOK /e+ehEo/9MNeVccDRPNShaLARV40tgCnjoMq/pDv65ZZbKtqF8Uc3ozB+Lpmc9ISZDgQ DC2iLnwKPjd9gYVs7RAivJ35fmxFp+zLEtofCpNYAGvOTjvPzDUsx7dUBVYG0X3VMrDg hpf5CXB/B9fS8iDN6yevcY7zjflxu9V63tWXxnKXtDwQ+UOq1Jb5elObzaAB30M4e+ul bonXbFeeEznsOEmwI953r5IrZWKbVAjoJDFC93QMgdIIwvfeqwTKEpCMxh3effBhEOE4 CDkQ== X-Forwarded-Encrypted: i=1; AJvYcCXnfyIUUTykCcZcYEADJitzYjzE1HMWhL4hcCx0XOlPe+cUuapcaRE3pBe35h61OoyYuDgdGNJTP2xb/iLKcwItAuAiDFdKKy/c7rZt X-Gm-Message-State: AOJu0YzJXMzXov1qspWf4LaNMHCqf0HIdI/iq8c1YR8u9Afx2eNk5BKy HN7acEIUHmkqIvlsx22oL29HIZGc8sPQf8KNPbYMpb2cdlACxZybbEOneHFxDVc= X-Google-Smtp-Source: AGHT+IHcoXJP3gEa+WaQYbFLEmPnvIPyvgKbTmvBrMFHfdFfqDYyn76MEt5EBTgP2Xe0lQpJygXuEg== X-Received: by 2002:a05:651c:c1:b0:2ec:3cc6:e156 with SMTP id 38308e7fff4ca-2ec3cc6e17amr420021fa.50.1718718304493; Tue, 18 Jun 2024 06:45:04 -0700 (PDT) Received: from [127.0.1.1] (frhb82016ds.ikexpress.com. [185.246.87.17]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3607509c8d8sm14160147f8f.32.2024.06.18.06.45.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Jun 2024 06:45:04 -0700 (PDT) From: Guillaume Stols Date: Tue, 18 Jun 2024 13:45:00 +0000 Subject: [PATCH v2] iio: adc: ad7606: remove frstdata check for serial mode 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: <20240618-cleanup-ad7606-v2-1-b0fd015586aa@baylibre.com> X-B4-Tracking: v=1; b=H4sIAFuPcWYC/13MQQ6CMBCF4auQWVvTmWABV97DsCjtKJMgkFYbC eHuVhI3Lv+XvG+FyEE4wrlYIXCSKNOYgw4FuN6Od1bicwNpKnWJRrmB7fialfWV0UahQSb2TY1 1B/k0B77Jewevbe5e4nMKy+4n/K4/qvqnEipUJ0eWGmPIaXvp7DJIF/jopge027Z9AG3Is5qvA AAA To: Lars-Peter Clausen , Michael Hennerich , Jonathan Cameron Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, jstephan@baylibre.com, dlechner@baylibre.com, Guillaume Stols X-Mailer: b4 0.14.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1718718304; l=5944; i=gstols@baylibre.com; s=20240417; h=from:subject:message-id; bh=ae4pwjFhUlQcrVR7mQTgRv94AhEmxr16sF6IEJpjbGg=; b=UFHUE5RnD+Ur1KhALafDx0bqfNAbkQsQkxH64MYMSYGUORjK+ET2QDnqADfUI0UmPjBlXyHqd X5JQ/hyS94wCJ0gmqDESOfgMXIJpWCN0AmbvP5Dapgg5UbaFPtV+XGy X-Developer-Key: i=gstols@baylibre.com; a=ed25519; pk=XvMm5WHuV67sGYOJZqIYzXndbaJOlNd8Q6li6vnb4Cs= Frstdata pin is set high during the first sample's transmission and then set low. This code chunk attempts to recover from an eventual glitch in the clock by checking frstdata state after reading the first channel's sample. Currently, in serial mode, this check happens AFTER the 16th pulse, and if frstdata is not set it resets the device and returns EINVAL. According to the datasheet, "The FRSTDATA output returns to a logic low following the 16th SCLK falling edge.", thus after the 16th pulse, the check will always be true, and the driver will not work as expected. Thus it must be removed for serial mode. Signed-off-by: Guillaume Stols --- Changes in v2: - Remove frstdata check only for the serial interface as suggested by Michael Hennerich. - Link to v1: https://lore.kernel.org/r/20240417-cleanup-ad7606-v1-1-5c2a2= 9662c0a@baylibre.com --- drivers/iio/adc/ad7606.c | 28 ++----------------------- drivers/iio/adc/ad7606.h | 2 ++ drivers/iio/adc/ad7606_par.c | 49 ++++++++++++++++++++++++++++++++++++++++= +--- 3 files changed, 50 insertions(+), 29 deletions(-) diff --git a/drivers/iio/adc/ad7606.c b/drivers/iio/adc/ad7606.c index 3a417595294f..c321c6ef48df 100644 --- a/drivers/iio/adc/ad7606.c +++ b/drivers/iio/adc/ad7606.c @@ -49,7 +49,7 @@ static const unsigned int ad7616_oversampling_avail[8] = =3D { 1, 2, 4, 8, 16, 32, 64, 128, }; =20 -static int ad7606_reset(struct ad7606_state *st) +int ad7606_reset(struct ad7606_state *st) { if (st->gpio_reset) { gpiod_set_value(st->gpio_reset, 1); @@ -60,6 +60,7 @@ static int ad7606_reset(struct ad7606_state *st) =20 return -ENODEV; } +EXPORT_SYMBOL_NS_GPL(ad7606_reset, IIO_AD7606); =20 static int ad7606_reg_access(struct iio_dev *indio_dev, unsigned int reg, @@ -88,31 +89,6 @@ static int ad7606_read_samples(struct ad7606_state *st) { unsigned int num =3D st->chip_info->num_channels - 1; u16 *data =3D st->data; - int ret; - - /* - * The frstdata signal is set to high while and after reading the sample - * of the first channel and low for all other channels. This can be used - * to check that the incoming data is correctly aligned. During normal - * operation the data should never become unaligned, but some glitch or - * electrostatic discharge might cause an extra read or clock cycle. - * Monitoring the frstdata signal allows to recover from such failure - * situations. - */ - - if (st->gpio_frstdata) { - ret =3D st->bops->read_block(st->dev, 1, data); - if (ret) - return ret; - - if (!gpiod_get_value(st->gpio_frstdata)) { - ad7606_reset(st); - return -EIO; - } - - data++; - num--; - } =20 return st->bops->read_block(st->dev, num, data); } diff --git a/drivers/iio/adc/ad7606.h b/drivers/iio/adc/ad7606.h index 0c6a88cc4695..6649e84d25de 100644 --- a/drivers/iio/adc/ad7606.h +++ b/drivers/iio/adc/ad7606.h @@ -151,6 +151,8 @@ int ad7606_probe(struct device *dev, int irq, void __io= mem *base_address, const char *name, unsigned int id, const struct ad7606_bus_ops *bops); =20 +int ad7606_reset(struct ad7606_state *st); + enum ad7606_supported_device_ids { ID_AD7605_4, ID_AD7606_8, diff --git a/drivers/iio/adc/ad7606_par.c b/drivers/iio/adc/ad7606_par.c index d8408052262e..1f7050297b64 100644 --- a/drivers/iio/adc/ad7606_par.c +++ b/drivers/iio/adc/ad7606_par.c @@ -7,6 +7,7 @@ =20 #include #include +#include #include #include #include @@ -21,8 +22,30 @@ static int ad7606_par16_read_block(struct device *dev, struct iio_dev *indio_dev =3D dev_get_drvdata(dev); struct ad7606_state *st =3D iio_priv(indio_dev); =20 - insw((unsigned long)st->base_address, buf, count); =20 + /* + * On the parallel interface, the frstdata signal is set to high while + * and after reading the sample of the first channel and low for all + * other channels. This can be used to check that the incoming data is + * correctly aligned. During normal operation the data should never + * become unaligned, but some glitch or electrostatic discharge might + * cause an extra read or clock cycle. Monitoring the frstdata signal + * allows to recover from such failure situations. + */ + int num =3D count; + u16 *_buf =3D buf; + + if (st->gpio_frstdata) { + insw((unsigned long)st->base_address, _buf, 1); + if (!gpiod_get_value(st->gpio_frstdata)) { + ad7606_reset(st); + return -EIO; + } + _buf++; + num--; + } + insw((unsigned long)st->base_address, _buf, num) +; return 0; } =20 @@ -35,8 +58,28 @@ static int ad7606_par8_read_block(struct device *dev, { struct iio_dev *indio_dev =3D dev_get_drvdata(dev); struct ad7606_state *st =3D iio_priv(indio_dev); - - insb((unsigned long)st->base_address, buf, count * 2); + /* + * On the parallel interface, the frstdata signal is set to high while + * and after reading the sample of the first channel and low for all + * other channels. This can be used to check that the incoming data is + * correctly aligned. During normal operation the data should never + * become unaligned, but some glitch or electrostatic discharge might + * cause an extra read or clock cycle. Monitoring the frstdata signal + * allows to recover from such failure situations. + */ + int num =3D count; + u16 *_buf =3D buf; + + if (st->gpio_frstdata) { + insb((unsigned long)st->base_address, _buf, 2); + if (!gpiod_get_value(st->gpio_frstdata)) { + ad7606_reset(st); + return -EIO; + } + _buf++; + num--; + } + insb((unsigned long)st->base_address, _buf, num * 2); =20 return 0; } --- base-commit: 07d4d0bb4a8ddcc463ed599b22f510d5926c2495 change-id: 20240416-cleanup-ad7606-161e2ed9818b Best regards, --=20 Guillaume Stols