From patchwork Thu Oct 24 17:17:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= X-Patchwork-Id: 13849468 Received: from mail-wm1-f47.google.com (mail-wm1-f47.google.com [209.85.128.47]) (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 005FD1F76AF for ; Thu, 24 Oct 2024 17:17:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729790246; cv=none; b=AtCo8ESVAhI9jRfoQPbUfM51SXpBqgwmxQhAMhrNyatslPs2G4FOQWa4ZJuj9yXxcieFpWK2gfvt/2Na8W606pdUjr6MWqrPCi4K9K9B3eN9nesEGz99I0jR941Ff2c3bhJqWoM+dqQ5xGm8YDokZmw3erJjg7sv77uemF4bfu4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729790246; c=relaxed/simple; bh=zlE41GBJu59TMSD2fDX4lXwHPLrJK2KzJ136R6Krqkk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=JKNAnO3kmRBQ9wowpvD4wcFVK2QKsibvreWp/RB+/rXhy8URdgMmpjNHouJkyAAdHJU4IzGwImbNfxiVb6sjQrrr8wTfaSEZp4tNrfklrAGDQLwkXSMA8hBadDwBHHZBNhyNhwSraFjjHcf4kVJSVDhhx9uwGvEKL9WMvMT3l3o= 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=NPsDTjQa; arc=none smtp.client-ip=209.85.128.47 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="NPsDTjQa" Received: by mail-wm1-f47.google.com with SMTP id 5b1f17b1804b1-4315e9e9642so11315185e9.0 for ; Thu, 24 Oct 2024 10:17:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1729790242; x=1730395042; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=CLsiSxWUPNvsZJPZR5fuMuMm4AIy+Kqvu4+UUkiUfo0=; b=NPsDTjQa6OW72VRwsGf3gVnPe78T0KCjvQHlSobUYsR6UIkDm3dPcvdKUiZteJyrii u8n7jRjs+1wL+7jVawbxuUpYY1t9om7eSd1fdwm7KgrTvJ4RYQ4/GeCwjqCwalJaB5i1 2xZKlGI09ysJIK75inN6xD1KWlPhnY+ckWccjp0bZPOrge3h6o42OW2kvyhZ1ixo4KB9 pZnaRTRhifOz47qeF84xX8cP2Njm0izGzRDO4T62PwmQYJH5GXzlUsSxa5Q0lhut3dww TKmdbrtGt5RDL3Z/ovs6Tgh23WL0CWv9ZGlSZOeVWIZhl/GdV7caZd+qEX9eD2q8Q4Ch IcQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729790242; x=1730395042; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=CLsiSxWUPNvsZJPZR5fuMuMm4AIy+Kqvu4+UUkiUfo0=; b=nWbHM/iepJ0b4Wt6iiJGbSG6AKt/VIMRpddQdZ/MRp6zACgxpzak48U8Jj/xqrpyis RXnRxGIbAVcCO54KF+rL3FqqL35nxxufp4MvXkhTgaxHP+WLvXNTy6uyQQWBAaHMRf8+ NO3r94X1Gdx2Y2WRZtpRLsws3l7Qb3Kb3jF7Dw/5VFuQ9P/orD8LfVelCIz+4FPovtDV awT9Jb7rqMpZAjddKVteTxFs22K8T+NwTUecRGBOaFGQmz8OzaEu4Kjqy07DzNSN8ryT UY964V31DtDARXISX7zzNbbBkKAqtHII4AysgA4W3M3lPLuBfoCgdtuwnRl1+320Xg0u WCDg== X-Forwarded-Encrypted: i=1; AJvYcCX+bS6y9ySIQAZFO/I9CQ6aWPB/0GCpIAZ69q1Q56IMyQK96/TEOjXrW6r8ijzAvbtMQd/t7F2lItw=@vger.kernel.org X-Gm-Message-State: AOJu0Yx7fyMvP2ktiSP40p1MCHR5wR+s6Gx1gDKATvbXKVGvqT6+TsRl c01zdDoyNrvFjTxM91jeE95HJFxAMZB3XXFIooa9f9BNVFGye3DzOzFuQje8ZzA= X-Google-Smtp-Source: AGHT+IESqW79443CxQLiMuKk/NV5ULmdPHVLHkIii+DlSoOtgBD+H4mKhpphtCgsNAV0EifFLKqvCQ== X-Received: by 2002:a05:6000:4581:b0:37d:41df:136b with SMTP id ffacd0b85a97d-37efcf06102mr4256968f8f.13.1729790242259; Thu, 24 Oct 2024 10:17:22 -0700 (PDT) Received: from localhost (p50915d2d.dip0.t-ipconnect.de. [80.145.93.45]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-37ee0a57e0fsm11777830f8f.47.2024.10.24.10.17.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Oct 2024 10:17:21 -0700 (PDT) From: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= To: Alexandru Tachici , Conor Dooley , David Lechner , Dumitru Ceclan , Jonathan Cameron , Krzysztof Kozlowski , Lars-Peter Clausen , Michael Hennerich , Nuno Sa , Rob Herring Cc: devicetree@vger.kernel.org, linux-iio@vger.kernel.org Subject: [PATCH 1/3] dt-bindings: iio: adc: adi,ad7124: Allow specifications of a gpio for irq line Date: Thu, 24 Oct 2024 19:17:03 +0200 Message-ID: <20241024171703.201436-6-u.kleine-koenig@baylibre.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241024171703.201436-5-u.kleine-koenig@baylibre.com> References: <20241024171703.201436-5-u.kleine-koenig@baylibre.com> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1935; i=u.kleine-koenig@baylibre.com; h=from:subject; bh=zlE41GBJu59TMSD2fDX4lXwHPLrJK2KzJ136R6Krqkk=; b=owEBbQGS/pANAwAKAY+A+1h9Ev5OAcsmYgBnGoESlhys6gUhgUbMHsAanellCVG+8TzzyJ0E0 jiGKoMP0P+JATMEAAEKAB0WIQQ/gaxpOnoeWYmt/tOPgPtYfRL+TgUCZxqBEgAKCRCPgPtYfRL+ Tuw0CAClZUazIjN2cewYqGTKLizqs9zQh+P7XJRvejAaYL8Z/B3f0m4q92KzoxSW0rkLKg6sui1 NvTiYzU+uPbgAZ5XJKP/S4H+iBnuze/9NoxQ+uDfK2h9YqRwjM0GjTbNy35+PajWxD2wguAfkAw rgaFL+c6FvhMzc/n0di3C1mnQ1we1eM+SvU/SxXBNbZTyhrnOtX721r+L0KrvdF/BDmtjMLsrUI 1sbMTeGq5VGTfLHJBb7B8SOqmmJKEq1gPcYKMuHDAlI4HBgFleRQ/s+B5gg0gS09d0o8c96lTTH 5vmGLVP4Ri6Ky3cTE16LoiTkQdH+5RVohU3lGH8Xpu1lLCav X-Developer-Key: i=u.kleine-koenig@baylibre.com; a=openpgp; fpr=0D2511F322BFAB1C1580266BE2DCDD9132669BD6 For the AD7124 chip the logical irq line (̅R̅D̅Y) is physically on the same pin as the spi MISO output (DOUT) and so reading a register might trigger an interrupt. For correct operation it's critical that the actual state of the pin can be read to judge if an interrupt event is a real one or just a spurious one triggered by toggling the line in its MISO mode. Allow specification of an "interrupt-gpios" property instead of a plain interrupt. The semantic is that the GPIO's interrupt is to be used as event source and reading the GPIO can be used to differentiate between a real event and one triggered by MISO. Signed-off-by: Uwe Kleine-König --- .../devicetree/bindings/iio/adc/adi,ad7124.yaml | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/Documentation/devicetree/bindings/iio/adc/adi,ad7124.yaml b/Documentation/devicetree/bindings/iio/adc/adi,ad7124.yaml index 35ed04350e28..feb3a41a148e 100644 --- a/Documentation/devicetree/bindings/iio/adc/adi,ad7124.yaml +++ b/Documentation/devicetree/bindings/iio/adc/adi,ad7124.yaml @@ -37,6 +37,9 @@ properties: description: IRQ line for the ADC maxItems: 1 + interrupt-gpios: + description: GPIO reading the interrupt line + '#address-cells': const: 1 @@ -57,7 +60,12 @@ required: - reg - clocks - clock-names - - interrupts + +oneOf: + - required: + - interrupts + - required: + - interrupt-gpios patternProperties: "^channel@([0-9]|1[0-5])$": @@ -119,8 +127,7 @@ examples: compatible = "adi,ad7124-4"; reg = <0>; spi-max-frequency = <5000000>; - interrupts = <25 2>; - interrupt-parent = <&gpio>; + interrupt-gpios = <&gpio 25 2>; refin1-supply = <&adc_vref>; clocks = <&ad7124_mclk>; clock-names = "mclk"; From patchwork Thu Oct 24 17:17:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= X-Patchwork-Id: 13849469 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 6BF171F9EB5 for ; Thu, 24 Oct 2024 17:17:25 +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=1729790247; cv=none; b=UaGHApuLKhCmI2G9zh0mBdAwE43oe8BttKznZMpZ4bvGGoCwDU9aqwL0D1eBX+2kC/dlMb/PQvjri42MsJKDrz8YsaXwpUtpxl8lEZfOj+yLvuxsGnuvQxyIpYQ4IwP/BiVdz3KtrsRxQZs97Asew2yAIILDgkdCW8ME6u8hedI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729790247; c=relaxed/simple; bh=7c3XPE4sMerF2DKbilOR+hTQTWJgS2t/eqp8pnU8OZI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=nidSORP/LfHplSAsCyPkQVMnCi/wxTdhpzYmdgUGxmMFV15tNRnFxnPAyhwQ259Mp9dXDkv81RJxarX2/Fp5PK6q8ib9TIXWKxBpm1Niv+iRilJEtdXUlWw9YHmOhSuXhCOvmLrybT7DwAttqzyAQqrt/QKyHT26b4MbKd+m/do= 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=zDlvrsM0; 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="zDlvrsM0" Received: by mail-wm1-f44.google.com with SMTP id 5b1f17b1804b1-4316a44d1bbso11111425e9.3 for ; Thu, 24 Oct 2024 10:17:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1729790244; x=1730395044; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=JJ0YkQuoJdLlVLGTP0MTDUu5okEHNcKdbWjh3yi4wVk=; b=zDlvrsM0JGoTE1PoMeN5m2kmeHglOQdFbTgfWmQOo0t4foYW4R5Hbie35KDV739tCW bw8a3swL+ZxLDqNcjqsD9CMLHHdQ85aQTQtS5NyHn0aKscfg2iRqWtI27ZnVGsE6STCL ki+YvqOceQy9hn/8P8W642IgKsDT8XZ02d7TRJ0nqqm48yUKbO3tybjpF3YpgeRwF92s hbtPwJhH4WojujQwLBb4OGWp4i6PX5GDhWAwb4Dr2FQVGk+Jjuw8BKGtQHXy3N3V9jeb NlBg3zh9A7UHwyc9P03+FcuGUzCQQ7ptAAIvzR1+X9pnfVeL+R1XPctuHQ+yz01tt2TB n+mQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729790244; x=1730395044; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=JJ0YkQuoJdLlVLGTP0MTDUu5okEHNcKdbWjh3yi4wVk=; b=hCiaJX8lsygxTIOMq2+fo682iPuetap0plcZlPPGGujdx/bSI8K6sEpOQTsjrIc5Jw ZDB1r7eIHtnaJ+Z46+/Ke//Y9estJa8JVXVBFwrpEcGucsgqzwFkwrwmgGPA3t134jDb p+kt6Zq5GmMOCeGythzAk4BWkOUC4ZBTpMXep2kZ9Tjca7mPU+/Zfjw9yyDDCkdpOTCU a9Pzu7YWSA1yu7Wc4Wa93Yq0LO+PgS2Nn1h447Lqa8C17StNu8yACCvDQCgPPMQ4BKnY HdeHYniFKi9wNK3zfbtXqEKm6EsSwegfgZkqKYx4LbLK7K2mlIo/r5R2x57Mr6b7doHQ 6Etg== X-Forwarded-Encrypted: i=1; AJvYcCVAx8VtUr6ARkyOR4/3ykYg3bRayv2W51seWHAEal9xqtmJo+4rwS6Zm/qjgXy0V5RTskThmaJPDL0=@vger.kernel.org X-Gm-Message-State: AOJu0YwrFlNl/fzjOmqTr8jDFX5+vvFJl3w8Pzsmdq7PROFmIUpBwoDl UTQEeoKaysBbgfgTJ4WwVCWxDUm0DUjXmSUfwHziGOUo2SpajaXgzjGs6YAWAUk= X-Google-Smtp-Source: AGHT+IEeQwpYwVOIs9arLkIWI0SEfT5C+CW6ck7pWIh7VXvYuWJ66pPGwXx2a3vFVKI6taFA+heREA== X-Received: by 2002:a5d:504f:0:b0:37c:c9ae:23fb with SMTP id ffacd0b85a97d-37efcf733acmr5051507f8f.40.1729790243666; Thu, 24 Oct 2024 10:17:23 -0700 (PDT) Received: from localhost (p50915d2d.dip0.t-ipconnect.de. [80.145.93.45]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-37ee0b9433asm11781980f8f.80.2024.10.24.10.17.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Oct 2024 10:17:23 -0700 (PDT) From: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= To: Alexandru Tachici , Conor Dooley , David Lechner , Dumitru Ceclan , Jonathan Cameron , Krzysztof Kozlowski , Lars-Peter Clausen , Michael Hennerich , Nuno Sa , Rob Herring Cc: devicetree@vger.kernel.org, linux-iio@vger.kernel.org Subject: [PATCH 2/3] iio: adc: ad_sigma_delta: Add support for reading irq status using a GPIO Date: Thu, 24 Oct 2024 19:17:04 +0200 Message-ID: <20241024171703.201436-7-u.kleine-koenig@baylibre.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241024171703.201436-5-u.kleine-koenig@baylibre.com> References: <20241024171703.201436-5-u.kleine-koenig@baylibre.com> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=3842; i=u.kleine-koenig@baylibre.com; h=from:subject; bh=7c3XPE4sMerF2DKbilOR+hTQTWJgS2t/eqp8pnU8OZI=; b=owEBbQGS/pANAwAKAY+A+1h9Ev5OAcsmYgBnGoEVEZsspt+rE5gBgarNkTUfUGB8QUH6E+iQu coE3+JY4+yJATMEAAEKAB0WIQQ/gaxpOnoeWYmt/tOPgPtYfRL+TgUCZxqBFQAKCRCPgPtYfRL+ TnVoB/97RBd2e0HgkMAwOs9HQodMWzGat9MW3Y7nlpNfvhalzzVNgoJFmYoGPTTucueDbWxbLBt DcbjxJ+dSwcL0Dmchtj2l0XjwFjJuMWQ2a6v9hAriJfRnVD39SfVs24qH8BWP7/2Orx5xcghksq jokgIFJCIlz7D9O8EXX/IPxZYXU/VCXHLXQYeE+CmHBHv7ufbxTjq4wazGcy2vZ6YdVidSOsm/w O+zSALmHi4/wD0G5hPtB27n+ENQ7+0UHBUwAdx0Cbnyuo+m5S7GEr4pWvYHpzMnwhmWpVsG1OqN h192+nJ6l5cAU4jBEnaSf9tvspsxMotCd7OAuyFVsvh+Xsdl X-Developer-Key: i=u.kleine-koenig@baylibre.com; a=openpgp; fpr=0D2511F322BFAB1C1580266BE2DCDD9132669BD6 Some of the ADCs by Analog signal their irq condition on the MISO line. So typically that line is connected to an SPI controller and a GPIO. The GPIO is used as input and the respective interrupt is enabled when the last SPI transfer is completed. Depending on the GPIO controller the toggling MISO line might make the interrupt pending even while it's masked. In that case the irq handler is called immediately after irq_enable() and so before the device actually pulls that line low which results in non-sense values being reported to the upper layers. The only way to find out if the line was actually pulled low is to read the GPIO. (There is a flag in AD7124's status register that also signals if an interrupt was asserted, but reading that register toggles the MISO line and so might trigger another spurious interrupt.) Add the possibility to specify an interrupt GPIO in the machine description instead of a plain interrupt. This GPIO is used as interrupt source and to check if the irq line is actually active in the irq handler. Signed-off-by: Uwe Kleine-König --- drivers/iio/adc/ad_sigma_delta.c | 36 +++++++++++++++++++++----- include/linux/iio/adc/ad_sigma_delta.h | 1 + 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/drivers/iio/adc/ad_sigma_delta.c b/drivers/iio/adc/ad_sigma_delta.c index e2bed2d648f2..d35602cfb093 100644 --- a/drivers/iio/adc/ad_sigma_delta.c +++ b/drivers/iio/adc/ad_sigma_delta.c @@ -539,12 +539,29 @@ static irqreturn_t ad_sd_data_rdy_trig_poll(int irq, void *private) { struct ad_sigma_delta *sigma_delta = private; - complete(&sigma_delta->completion); - disable_irq_nosync(irq); - sigma_delta->irq_dis = true; - iio_trigger_poll(sigma_delta->trig); + /* + * AD7124 and a few others use the same physical line for interrupt + * reporting (nRDY) and MISO. + * As MISO toggles when reading a register, this likely results in a + * pending interrupt. This has two consequences: a) The irq might + * trigger immediately after it's enabled even though the conversion + * isn't done yet; and b) checking the STATUS register's nRDY flag is + * off-limits as reading that would trigger another irq event. + * + * So read the MOSI line as GPIO (if available) and only trigger the irq + * if the line is active. + */ - return IRQ_HANDLED; + if (!sigma_delta->irq_gpiod || gpiod_get_value(sigma_delta->irq_gpiod)) { + complete(&sigma_delta->completion); + disable_irq_nosync(irq); + sigma_delta->irq_dis = true; + iio_trigger_poll(sigma_delta->trig); + + return IRQ_HANDLED; + } else { + return IRQ_NONE; + } } /** @@ -676,8 +693,15 @@ int ad_sd_init(struct ad_sigma_delta *sigma_delta, struct iio_dev *indio_dev, if (info->irq_line) sigma_delta->irq_line = info->irq_line; - else + else if (spi->irq) sigma_delta->irq_line = spi->irq; + else { + sigma_delta->irq_gpiod = devm_gpiod_get(&spi->dev, "interrupt", GPIOD_IN); + if (IS_ERR(sigma_delta->irq_gpiod)) + return dev_err_probe(&spi->dev, PTR_ERR(sigma_delta->irq_gpiod), + "Failed to find interrupt gpio\n"); + sigma_delta->irq_line = gpiod_to_irq(sigma_delta->irq_gpiod); + } iio_device_set_drvdata(indio_dev, sigma_delta); diff --git a/include/linux/iio/adc/ad_sigma_delta.h b/include/linux/iio/adc/ad_sigma_delta.h index f8c1d2505940..fc0141e0f0ef 100644 --- a/include/linux/iio/adc/ad_sigma_delta.h +++ b/include/linux/iio/adc/ad_sigma_delta.h @@ -96,6 +96,7 @@ struct ad_sigma_delta { unsigned int active_slots; unsigned int current_slot; unsigned int num_slots; + struct gpio_desc *irq_gpiod; int irq_line; bool status_appended; /* map slots to channels in order to know what to expect from devices */ From patchwork Thu Oct 24 17:17:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= X-Patchwork-Id: 13849470 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 F11191F8EE5 for ; Thu, 24 Oct 2024 17:17:27 +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=1729790251; cv=none; b=L/i8t+o8b2345M4cjZiNH7BoVjz3aFEuyhpiB4fRGhWT7L+4kk6jKwgHv7X2nfXtheYGDXcgjC2gbuvMeGJswQx5cCJXXSYiyfYO350lgn2McdqEth3tRIaK5H5L/MSuL4h8fqKOK8v8KFAfce/rYs2xsQNP2kda0A6kkVrEkcg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729790251; c=relaxed/simple; bh=76N+Si6K+8dgLWMJ9V3NKmwxxyz+jGXcxE3eF50Hh6M=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=cU8WlFPcHIK8b5Z6ouAX3ZgV8uo4SDCzRCTe+SRB2LCDX6uAPPmk/ljpuc4lTrj9QhQdAsjASASmjnasDLWSvUP//u4bYnXcZwNyT45dyr8zMA/FUZv+Mku+T2kGsNOpGYY80byQxtSzq4zPopzDyy2VsM1RYeqPUamkvjyhO88= 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=JiEZ2i5L; 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="JiEZ2i5L" Received: by mail-wm1-f44.google.com with SMTP id 5b1f17b1804b1-4316e9f4a40so12362385e9.2 for ; Thu, 24 Oct 2024 10:17:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1729790246; x=1730395046; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=CaTrXkFXaNRHKXBh+COBpt8a1vEye13/gPVK1ExC51U=; b=JiEZ2i5LInBI/oylnbw+zVcxtMnMYLfWF3OEvq3KvN9jDXY6CGR2z97RVEz31n4dAh B+5DeKwQVjch11kVYFjMruJ4w/JWm38VEVz3Kl0iw/4o0NyUOilrtiSqsj95dw4YEKBz AQskG8IfIqwLjyzFjfCosL1BiESPooXBVeUJ8gleLGApNHF5Sb/ZC88vZH/CEF611x+D Z84wp1Tb6n+kNp+njhlqBAATfCklj87ZzoCABmo1s+PvJmN71M5ti536ekHVEu8uRrQe 5UE+f99Rw9nhmYJUqmocpSIaImiD+YOMsArHRdzqhXQCSeqB0x73So3QN4uvo/v6db6V ME2A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729790246; x=1730395046; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=CaTrXkFXaNRHKXBh+COBpt8a1vEye13/gPVK1ExC51U=; b=hJmyRaB3AP5jkNHdEj40PW7pmOjQkBF8MClqBJrUm2SzdjtgMNagllbzylJTXfV+7B EiOep4Au0uwMW5OSJXB0jcdbZUn9Slihsd7pNm18paq0A/paeiOcY4IIhEh54EAbtvqn Q/wjF7TY65lxdCf+DgAw882D9F9Y6jjvtXHsNVS9bqfi8fd0yc6d3arJVz6mY0sJGilz U6cQYYJ47+F/pi9ZDPcvmYXgK7NTkltWYXAv+j3c7Ju9X2QNMK6vmH8m+x2iipEzTS49 zvmUTuyVFUG7Ov+ZOzL2jLyj0IVoXHwHTfi2jd663B6aYHlLX1V3ht/+nlV6lJwDWJbF CugQ== X-Forwarded-Encrypted: i=1; AJvYcCXSyHFcCXvdwnHP7ZbamegPdkNSoIoSF9Ks36apn1qETCTf6kC0DrGAvCU9UgN8NXFPyPe+hB0u5wg=@vger.kernel.org X-Gm-Message-State: AOJu0YzNZa7v8G+Tik103QQabqc5bX/3LHfvn3+8PEzcIwkzFyHm+C3i GKBmrAnN59NZzfU2cFW8gNQeiWGUxAHrxDjTl6ur6HUVJcXTgbtZrq/kQXhoS2g= X-Google-Smtp-Source: AGHT+IEwbgudZZknJJI3QPRz8S6wAXEhaDb0EsLnluZmeyI6CkuOGi/iWYa0RWHMwkgvamc84C7sow== X-Received: by 2002:a05:600c:310e:b0:426:602d:a246 with SMTP id 5b1f17b1804b1-4318c77ee56mr24494575e9.32.1729790245996; Thu, 24 Oct 2024 10:17:25 -0700 (PDT) Received: from localhost (p50915d2d.dip0.t-ipconnect.de. [80.145.93.45]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-43186bfd059sm51365265e9.27.2024.10.24.10.17.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Oct 2024 10:17:24 -0700 (PDT) From: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= To: Alexandru Tachici , Conor Dooley , David Lechner , Dumitru Ceclan , Jonathan Cameron , Krzysztof Kozlowski , Lars-Peter Clausen , Michael Hennerich , Nuno Sa , Rob Herring Cc: devicetree@vger.kernel.org, linux-iio@vger.kernel.org Subject: [PATCH 3/3] iio: adc: ad7124: Disable all channels at probe time Date: Thu, 24 Oct 2024 19:17:05 +0200 Message-ID: <20241024171703.201436-8-u.kleine-koenig@baylibre.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241024171703.201436-5-u.kleine-koenig@baylibre.com> References: <20241024171703.201436-5-u.kleine-koenig@baylibre.com> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1380; i=u.kleine-koenig@baylibre.com; h=from:subject; bh=76N+Si6K+8dgLWMJ9V3NKmwxxyz+jGXcxE3eF50Hh6M=; b=owEBbQGS/pANAwAKAY+A+1h9Ev5OAcsmYgBnGoEXamHKqM9O+c9WtTaN+6LwCefEKyEwZ/S8C gUvJD9dLpiJATMEAAEKAB0WIQQ/gaxpOnoeWYmt/tOPgPtYfRL+TgUCZxqBFwAKCRCPgPtYfRL+ Tp7UB/sHCxfRTC1Eo/unYY4t2veNOqHcpXdM4ubfIKORn11mWF9H2TezUlEJwGnKCwVSNmYqV4e LqIVVcz9dlv02GNMVmpKpUKd+3zzvpWKsInXrLA8GIgl5Bjz9SD9FcOSudiYldpoSiOkSorSW2d k+ye4Wwpe66wM2vn3fiDzZolHSAWp3ikLeRFdL0CXhldseSrfoYjwIsA6I5ocCEs5FyX27YvMlg iW/VtXCcap7aNv5GmWbzTjP3D9H7OF04uB47H64+sTtEdYXXD52p5yiP2FViZj0D4rfAK4lg4oR Mk+N0vv9P3nAUGTo4XzNYzwsW5JRe7wNjJp0Hj1JdGbSUyoR X-Developer-Key: i=u.kleine-koenig@baylibre.com; a=openpgp; fpr=0D2511F322BFAB1C1580266BE2DCDD9132669BD6 When during a measurement two channels are enabled, two measurements are done that are reported sequencially in the DATA register. As the code triggered by reading one of the sysfs properties expects that only one channel is enabled it only reads the first data set which might or might not belong to the intended channel. To prevent this situation disable all channels during probe. This fixes a problem in practise because the reset default for channel 0 is enabled. So all measurements before the first measurement on channel 0 (which disables channel 0 at the end) might report wrong values. Fixes: 7b8d045e497a ("iio: adc: ad7124: allow more than 8 channels") Signed-off-by: Uwe Kleine-König --- drivers/iio/adc/ad7124.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/iio/adc/ad7124.c b/drivers/iio/adc/ad7124.c index a5d91933f505..912ba6592560 100644 --- a/drivers/iio/adc/ad7124.c +++ b/drivers/iio/adc/ad7124.c @@ -917,6 +917,9 @@ static int ad7124_setup(struct ad7124_state *st) * set all channels to this default value. */ ad7124_set_channel_odr(st, i, 10); + + /* Disable all channels to prevent unintended conversions. */ + ad_sd_write_reg(&st->sd, AD7124_CHANNEL(i), 2, 0x0001); } ret = ad_sd_write_reg(&st->sd, AD7124_ADC_CONTROL, 2, st->adc_control);