From patchwork Fri Jun 23 11:33:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rasmus Villemoes X-Patchwork-Id: 13290398 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6FB2BEB64D7 for ; Fri, 23 Jun 2023 11:33:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231565AbjFWLdl (ORCPT ); Fri, 23 Jun 2023 07:33:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34936 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231271AbjFWLdj (ORCPT ); Fri, 23 Jun 2023 07:33:39 -0400 Received: from mail-lj1-x22e.google.com (mail-lj1-x22e.google.com [IPv6:2a00:1450:4864:20::22e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1E252189 for ; Fri, 23 Jun 2023 04:33:38 -0700 (PDT) Received: by mail-lj1-x22e.google.com with SMTP id 38308e7fff4ca-2b4790ff688so9196041fa.1 for ; Fri, 23 Jun 2023 04:33:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rasmusvillemoes.dk; s=google; t=1687520016; x=1690112016; 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=EANxw9UBUzWA7WzQeG9K7sXYK8CnMSeZWX1OlZIav4U=; b=Ix2dqtFrBO5aUTzp+iN7g0CGvt+EuKluKaj3KRVutb8wks84LIrJDwiXxfqZlgNbMk YguVNrMfj90prDQWzbBkDEzAdDHGDvP0DgG0seT0YrCqxWz70Fy30LrPxHAhH9rrPTfr V4svsdUztNIRRO9MNIm+LeTlcGxbjRq4nX/mw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687520016; x=1690112016; 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=EANxw9UBUzWA7WzQeG9K7sXYK8CnMSeZWX1OlZIav4U=; b=WnjSb13CUUcO/R9hGxfCUMA+/EcKBSNw/tq5npUwODTtDkIrOxxR7FebGxmq6D02ra 44Q8+UXhN3dcyjijVIAUwIUwaMUlul8qcYCyTlJRVyGYktz75FtvxkPvRLfCsQzQSC/A 2Qhkj+8E1Okm2zFn0xxWouhFp3MQmqGjTzUt8+fsMGF5sX4e/QlNipIIH48GRNxax0kR oU7U+6bydD1yjEariXahYhtraohpocfEIh3KMoPHd3B9JtGzA+fSwrbGfRYxXMmF7eeP L3VVR2d7vKtLDL9KTipfgCa25vAmnvfQc9s8mpCp6ExoucG+khsEjBDRsZ8nf6KQss1V cb9w== X-Gm-Message-State: AC+VfDzsCmrjvrdEnYX8MVNHW0tYzzrnOfL6RUq1WmujlfQKkFybuK7z 70eNLXG4XJbcG4O844Vrdnnisg== X-Google-Smtp-Source: ACHHUZ5qLRdl1/GZ8d6A85W9DZGBD6/3iSjmvHvCKmLac3QS4zT/ikOtVVLSZqYIVfruHpVOybcfYQ== X-Received: by 2002:a2e:7d0f:0:b0:2b5:81bc:43a8 with SMTP id y15-20020a2e7d0f000000b002b581bc43a8mr5965742ljc.0.1687520016335; Fri, 23 Jun 2023 04:33:36 -0700 (PDT) Received: from prevas-ravi.prevas.se ([81.216.59.226]) by smtp.gmail.com with ESMTPSA id n10-20020a2e720a000000b002b471efb253sm1711605ljc.46.2023.06.23.04.33.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Jun 2023 04:33:36 -0700 (PDT) From: Rasmus Villemoes To: Lars-Peter Clausen , Michael Hennerich , Cosmin Tanislav , Jonathan Cameron Cc: devicetree@vger.kernel.org, Krzysztof Kozlowski , Rob Herring , Rasmus Villemoes , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/2] iio: addac: ad74413r: wire up digital-input-threshold-microvolt DT property Date: Fri, 23 Jun 2023 13:33:26 +0200 Message-Id: <20230623113327.1062170-3-linux@rasmusvillemoes.dk> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20230623113327.1062170-1-linux@rasmusvillemoes.dk> References: <20230623113327.1062170-1-linux@rasmusvillemoes.dk> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org The threshold is common to all channels configured as digital input. So far, we have not seen the settings in the DIN_THRESH affecting functions other than digital input, but with a4cba07e64e6 ("iio: addac: ad74413: don't set DIN_SINK for functions other than digital input") in mind, do not read and apply the digital-input-threshold-microvolt setting unless at least one channel has been configured as one of the digital input variants. Signed-off-by: Rasmus Villemoes --- drivers/iio/addac/ad74413r.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/drivers/iio/addac/ad74413r.c b/drivers/iio/addac/ad74413r.c index e3366cf5eb31..efdd7fdd7ab9 100644 --- a/drivers/iio/addac/ad74413r.c +++ b/drivers/iio/addac/ad74413r.c @@ -129,6 +129,12 @@ struct ad74413r_state { #define AD74413R_GPO_CONFIG_COMPARATOR 0b011 #define AD74413R_GPO_CONFIG_HIGH_IMPEDANCE 0b100 +#define AD74413R_REG_DIN_THRESH 0x22 +#define AD74413R_DIN_COMP_THRESH_MASK GENMASK(5, 1) +#define AD74413R_DIN_THRESH_MODE BIT(0) +#define AD74413R_DIN_THRESH_MODE_16V BIT(0) +#define AD74413R_DIN_THRESH_MODE_AVDD 0 + #define AD74413R_REG_ADC_CONV_CTRL 0x23 #define AD74413R_CONV_SEQ_MASK GENMASK(9, 8) #define AD74413R_CONV_SEQ_ON 0b00 @@ -1446,6 +1452,20 @@ static int ad74413r_probe(struct spi_device *spi) } if (st->num_comparator_gpios) { + u32 thresh, val, mask; + + if (!device_property_read_u32(st->dev, "digital-input-threshold-microvolt", + &thresh)) { + val = thresh/500000 - 1; + val = FIELD_PREP(AD74413R_DIN_COMP_THRESH_MASK, val); + val |= AD74413R_DIN_THRESH_MODE_16V; + mask = AD74413R_DIN_COMP_THRESH_MASK | AD74413R_DIN_THRESH_MODE; + ret = regmap_update_bits(st->regmap, AD74413R_REG_DIN_THRESH, + mask, val); + if (ret) + return ret; + } + st->comp_gpiochip.owner = THIS_MODULE; st->comp_gpiochip.label = st->chip_info->name; st->comp_gpiochip.base = -1;