From patchwork Mon Mar 6 09:43:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rasmus Villemoes X-Patchwork-Id: 13160765 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 C5251C6FD1A for ; Mon, 6 Mar 2023 09:43:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230047AbjCFJnN (ORCPT ); Mon, 6 Mar 2023 04:43:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56272 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229707AbjCFJnM (ORCPT ); Mon, 6 Mar 2023 04:43:12 -0500 Received: from mail-lf1-x134.google.com (mail-lf1-x134.google.com [IPv6:2a00:1450:4864:20::134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 763CE206A3 for ; Mon, 6 Mar 2023 01:43:09 -0800 (PST) Received: by mail-lf1-x134.google.com with SMTP id j11so11809416lfg.13 for ; Mon, 06 Mar 2023 01:43:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rasmusvillemoes.dk; s=google; t=1678095788; 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=8K7TxC9ujka7az5qWZ0Yj+PA8VwUCDcIymczB4ue3v8=; b=aFKS2vQ/9k+skY1++q3trAV5GuR0ux9uZmknr0vtFJDh6nWnD0FSxSSDBtPnpTLnOg pt2BVDnb7VuMXz1DPWdBFErXAgWf3Si4T6OwMmEl6y4c06N1si5jafB9WnZ1+dpvpAI1 FiMpjCX7zSDiHPkWObq+IZwD4Dggjsk4+xHWo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678095788; 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=8K7TxC9ujka7az5qWZ0Yj+PA8VwUCDcIymczB4ue3v8=; b=Sgl2oPAuFXIRWIbPJHXYWoc1h9UDIO5q/Apw3FXR0qby5FntKyr2g3siwl1IwbfHwu b5zTh0di1lhgTLCnxWXRydUsg1ZgPt4N+bWVRjMOOnZJzqHr2xuWsYjGu4HVpL01IGGl K3AfDCyMb6OYVJny7X4bYmexLimQLUvIC3wzEa//rDnfSlJlb5/fshTFs6SJ0MT1RH9i IttW4wkpLHCiFUinsnR3FDBGpySCRN/5h4Tw/NEYd+CHtLBTx6emXO74U7ALPCvzEkgd pn7YwBZH6HS6CKDxVfkUL8JogNy3LS+On2tUr2klcrsosfYd7ZY2RazbVgRLqMpFCX/B Nd/w== X-Gm-Message-State: AO0yUKWjOXQPePK+t7x7HORVKb9MPM2NrVxzA1AVfTPZWaEO1hb2XslV OKpv+PIsJQeOR6eLDDqNWW/Xqw== X-Google-Smtp-Source: AK7set/EEjtZWbShl/9cou4SP3WB9m8PCl7zwjvqbkD4+okPV4JvEgzxiJnpwFXfPLHEOV7WcGNXjw== X-Received: by 2002:ac2:547c:0:b0:4b5:b06d:4300 with SMTP id e28-20020ac2547c000000b004b5b06d4300mr2766340lfn.29.1678095787838; Mon, 06 Mar 2023 01:43:07 -0800 (PST) Received: from prevas-ravi.prevas.se ([81.216.59.226]) by smtp.gmail.com with ESMTPSA id a22-20020a2e9816000000b002934ed148afsm1620091ljj.52.2023.03.06.01.43.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Mar 2023 01:43:07 -0800 (PST) From: Rasmus Villemoes To: Cosmin Tanislav , Lars-Peter Clausen , Michael Hennerich , Jonathan Cameron , Rob Herring , Krzysztof Kozlowski Cc: devicetree@vger.kernel.org, Rasmus Villemoes , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 1/2] dt-bindings: iio: ad74413r: allow setting sink current for digital input Date: Mon, 6 Mar 2023 10:43:00 +0100 Message-Id: <20230306094301.1357543-2-linux@rasmusvillemoes.dk> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20230306094301.1357543-1-linux@rasmusvillemoes.dk> References: <20230302134922.1120217-1-linux@rasmusvillemoes.dk> <20230306094301.1357543-1-linux@rasmusvillemoes.dk> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org Depending on the actual hardware wired up to a digital input channel, it may be necessary to configure the ad74413r to sink a small current. For example, in the case of a simple mechanical switch, the charge on the external 68 nF capacitor (cf. the data sheet's Figure 34) will keep the channel as reading high even after the switch is turned off again. Signed-off-by: Rasmus Villemoes Reviewed-by: Krzysztof Kozlowski --- .../devicetree/bindings/iio/addac/adi,ad74413r.yaml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Documentation/devicetree/bindings/iio/addac/adi,ad74413r.yaml b/Documentation/devicetree/bindings/iio/addac/adi,ad74413r.yaml index 9eb3ecc8bbc8..590ea7936ad7 100644 --- a/Documentation/devicetree/bindings/iio/addac/adi,ad74413r.yaml +++ b/Documentation/devicetree/bindings/iio/addac/adi,ad74413r.yaml @@ -101,6 +101,15 @@ patternProperties: When not configured as a comparator, the GPO will be treated as an output-only GPIO. + drive-strength-microamp: + description: | + For channels configured as digital input, this configures the sink + current. + minimum: 0 + maximum: 1800 + default: 0 + multipleOf: 120 + required: - reg From patchwork Mon Mar 6 09:43:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rasmus Villemoes X-Patchwork-Id: 13160766 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 122A3C6FD19 for ; Mon, 6 Mar 2023 09:43:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230100AbjCFJnP (ORCPT ); Mon, 6 Mar 2023 04:43:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56328 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229486AbjCFJnO (ORCPT ); Mon, 6 Mar 2023 04:43:14 -0500 Received: from mail-lj1-x22c.google.com (mail-lj1-x22c.google.com [IPv6:2a00:1450:4864:20::22c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A8D6821A27 for ; Mon, 6 Mar 2023 01:43:10 -0800 (PST) Received: by mail-lj1-x22c.google.com with SMTP id x6so8969117ljq.1 for ; Mon, 06 Mar 2023 01:43:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rasmusvillemoes.dk; s=google; t=1678095789; 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=zmz2nBmbaTO3qG2SmBLPZDQGKtRO+Ieydz7Ye8FP4As=; b=AvTMfeE/Sh6nyegcz8yd+g1v/9paXcicB1uPpofJwnbvMQyAlt7cBCR8azL8NTTpaX 3/LNu8m+KawTxRa1AAlYWkPCX9viBpSIceGoQaeV+TqMVaYZao7zTjIaFnmjqtwmTfcy Hmw9mlQu0XaZlACc8SoMglt1BlDV8OpzJJoEw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678095789; 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=zmz2nBmbaTO3qG2SmBLPZDQGKtRO+Ieydz7Ye8FP4As=; b=68l+EIbFgqjos4U3Zxd2IUxrMxjXfgwljNGlEr45azOuMJgLRT0c8HgT+dvwF2A/6f dQ4Q4T3fPvSHZMe2KZp8vWCaPstc/ERi8HEXjnSuSyaNg/RBl7TFE/v2meBuR0SbHdmP QyKT2dvOf9sCiWmiIF0IdNiftT2smqduyskkkdlaxdCm+TnyvDe26Lt8mFeZ8COimObH vQU5zrG0JDGlTZRD67mxUyYJJs9qBGqJnj/GF5L+/mGzdpxDLSJMVwBJr7sng4BePBJV ZTA4cuUTyQbFlDEaRpdfZC3QdlVFzD2SdhMImc2F7QdNJUAJ44fLW+U+OURTKKlArUrz G4ug== X-Gm-Message-State: AO0yUKXs1yK6QZ1NC9Ddq64UOIeN/8EUp47owN3K6ubGKEAEUpLBNpF2 xay1GtMAgBESwrTqropk9BCixw== X-Google-Smtp-Source: AK7set/pXVTPqmW95TTuDKezJ3g8v2qM1LMEWSb93i6C5mD8Y/D4z3Xo+hq6TQN0mrhY9LP5UzwdMQ== X-Received: by 2002:a2e:1505:0:b0:295:ba28:a42 with SMTP id s5-20020a2e1505000000b00295ba280a42mr3214076ljd.20.1678095788912; Mon, 06 Mar 2023 01:43:08 -0800 (PST) Received: from prevas-ravi.prevas.se ([81.216.59.226]) by smtp.gmail.com with ESMTPSA id a22-20020a2e9816000000b002934ed148afsm1620091ljj.52.2023.03.06.01.43.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Mar 2023 01:43:08 -0800 (PST) From: Rasmus Villemoes To: Lars-Peter Clausen , Michael Hennerich , Cosmin Tanislav , Jonathan Cameron Cc: devicetree@vger.kernel.org, Rob Herring , Rasmus Villemoes , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 2/2] iio: ad74413r: wire up support for drive-strength-microamp property Date: Mon, 6 Mar 2023 10:43:01 +0100 Message-Id: <20230306094301.1357543-3-linux@rasmusvillemoes.dk> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20230306094301.1357543-1-linux@rasmusvillemoes.dk> References: <20230302134922.1120217-1-linux@rasmusvillemoes.dk> <20230306094301.1357543-1-linux@rasmusvillemoes.dk> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org Use the value specified in the channel configuration node to populate the DIN_SINK field of the DIN_CONFIGx register. Signed-off-by: Rasmus Villemoes --- drivers/iio/addac/ad74413r.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/drivers/iio/addac/ad74413r.c b/drivers/iio/addac/ad74413r.c index f32c8c2fb26d..4395758dbaa6 100644 --- a/drivers/iio/addac/ad74413r.c +++ b/drivers/iio/addac/ad74413r.c @@ -39,6 +39,7 @@ struct ad74413r_chip_info { struct ad74413r_channel_config { u32 func; + u32 drive_strength; bool gpo_comparator; bool initialized; }; @@ -111,6 +112,7 @@ struct ad74413r_state { #define AD74413R_REG_DIN_CONFIG_X(x) (0x09 + (x)) #define AD74413R_DIN_DEBOUNCE_MASK GENMASK(4, 0) #define AD74413R_DIN_DEBOUNCE_LEN BIT(5) +#define AD74413R_DIN_SINK_MASK GENMASK(9, 6) #define AD74413R_REG_DAC_CODE_X(x) (0x16 + (x)) #define AD74413R_DAC_CODE_MAX GENMASK(12, 0) @@ -261,6 +263,18 @@ static int ad74413r_set_comp_debounce(struct ad74413r_state *st, val); } +static int ad74413r_set_comp_drive_strength(struct ad74413r_state *st, + unsigned int offset, + unsigned int strength) +{ + strength = min(strength, 1800U); + + return regmap_update_bits(st->regmap, AD74413R_REG_DIN_CONFIG_X(offset), + AD74413R_DIN_SINK_MASK, + FIELD_PREP(AD74413R_DIN_SINK_MASK, strength / 120)); +} + + static void ad74413r_gpio_set(struct gpio_chip *chip, unsigned int offset, int val) { @@ -1190,6 +1204,9 @@ static int ad74413r_parse_channel_config(struct iio_dev *indio_dev, config->gpo_comparator = fwnode_property_read_bool(channel_node, "adi,gpo-comparator"); + fwnode_property_read_u32(channel_node, "drive-strength-microamp", + &config->drive_strength); + if (!config->gpo_comparator) st->num_gpo_gpios++; @@ -1269,6 +1286,7 @@ static int ad74413r_setup_gpios(struct ad74413r_state *st) unsigned int gpo_gpio_i = 0; unsigned int i; u8 gpo_config; + u32 strength; int ret; for (i = 0; i < AD74413R_CHANNEL_MAX; i++) { @@ -1285,6 +1303,11 @@ static int ad74413r_setup_gpios(struct ad74413r_state *st) config->func == CH_FUNC_DIGITAL_INPUT_LOOP_POWER) st->comp_gpio_offsets[comp_gpio_i++] = i; + strength = config->drive_strength; + ret = ad74413r_set_comp_drive_strength(st, i, strength); + if (ret) + return ret; + ret = ad74413r_set_gpo_config(st, i, gpo_config); if (ret) return ret;