Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp3610779rwb; Sat, 12 Nov 2022 08:57:45 -0800 (PST) X-Google-Smtp-Source: AA0mqf7sKeWq1cI13E6weO8pU3F9UoaVfk9lFfSPTiH/j1AbyUKjZMgKJUE17wnwI8QSfFeXplp8 X-Received: by 2002:a63:3d7:0:b0:46f:1e8f:1630 with SMTP id 206-20020a6303d7000000b0046f1e8f1630mr5747848pgd.565.1668272264920; Sat, 12 Nov 2022 08:57:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668272264; cv=none; d=google.com; s=arc-20160816; b=ZPdtzXfgPxkKIMbfls6yqSxM1YbpgvGf+XMMGWl1rwX7BXQ5FFI11IrEc4DL3q9AmY 2arKWhH7blyMh++G6Kpj+oUye+l1T9fGEQVlL1s84LLEr9cHIKraSrdtqh3Xna5tlzf5 r7sSmarLFwtvRhbfTIpXdkgDEH+/io5HJWVV/9wa0N8fE33XJpuqj3xaulMZB8XKBpz+ plmIRKHGQmNcj1fV3TueuBRL9veM0tfu1H+y8NzjO4iYjhnKrsm4SiBREB3phrQi1QwE 0/STY5HRV78UP4LC6APIbZP6SAE4+JB8R2Y8I9//vsw2UJ+rl79fjhmh2H25P9GHuqTi wehQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=o6QaXorSWgHRyTtNi8WGVEJ9QcV1Ll84M4IAb1XyhPk=; b=dJ5hsVkF3Jm/5W3m8AHLIe9B1YjKXAUPo50v5X1JL6E8gccvnwUXRVKDJC7k6KH6Bu eYYIRQTe2x31lXMSiMS7lTi6Ll0smPhwXejEvCeDwG51Xv1q+JjIupd3UORMtPTSa1Xv Ld65eGGrPHyEKBsqtGzyqZt+1JeTk0b51k09rybIxutIFZeZ5kYPsr3vsStWvpa5AbGF G2rbRTvrjQ7oUf6ykRvEem60Dh5/s+aXYN2oTQP5UiOp3v6J5+9AJ8heDKWrHWCT7wMr FHw0iGSSoVU6oPfAyoE/8LifJPeGuUjk8jDer6RGT15w6YNeQKIHvx3ndpGNby7YUbgb SBMA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=jnNOYgEa; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r23-20020a634417000000b004597ddac1fasi5017788pga.533.2022.11.12.08.57.31; Sat, 12 Nov 2022 08:57:44 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=jnNOYgEa; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234981AbiKLQom (ORCPT + 91 others); Sat, 12 Nov 2022 11:44:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51402 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230170AbiKLQok (ORCPT ); Sat, 12 Nov 2022 11:44:40 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C4F6DDFC3; Sat, 12 Nov 2022 08:44:38 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 72CFEB80976; Sat, 12 Nov 2022 16:44:37 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9BFF1C433D6; Sat, 12 Nov 2022 16:44:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1668271476; bh=E21h76Ste+R/XmnRwrw2cGPAJ76iv8Ux/9BP47v6Mr8=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=jnNOYgEaGy+D83UtdT3ITvAmvw+hiW1aeuAupgoO0Vygya+1Q8/3/uE9uNi5+Re84 4VFRH5J14tCHmu4+XIC3BJs5NaP+7fQ8vG+ZsFZwNoBurjlDGXmgd+9rIl5eP5QIff EeMYFEeI+fHRXDX+fUNIpy1jVateIktbO8Q0o82zGz9+FfdAr/SINp1aj0BeWg76Or OBYMiKge3bEwzQF2fcyaItSMt/fu1LJCtVvalV0Ip7EJD1FBhoeLCqTt8MDQmNHATJ gTg1J4EA8SspfeIOMf93Rcrb3CpgMMCKk4GcshoEGytq1qxpm59uk61mTgEYRnoldv 0stLsFNTGF69A== Date: Sat, 12 Nov 2022 16:56:49 +0000 From: Jonathan Cameron To: Rasmus Villemoes Cc: Cosmin Tanislav , Lars-Peter Clausen , Michael Hennerich , devicetree@vger.kernel.org, Rob Herring , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 3/5] iio: addac: ad74413r: implement support for optional refin-supply Message-ID: <20221112165649.4e6c5cd3@jic23-huawei> In-Reply-To: <20221111143921.742194-4-linux@rasmusvillemoes.dk> References: <20221111143921.742194-1-linux@rasmusvillemoes.dk> <20221111143921.742194-4-linux@rasmusvillemoes.dk> X-Mailer: Claws Mail 4.1.1 (GTK 3.24.34; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 11 Nov 2022 15:39:19 +0100 Rasmus Villemoes wrote: > The ad74412r/ad74413r has an internal 2.5V reference output, which (by > tying the REFOUT pin to the REFIN pin) can be used in lieu of an > external 2.5V input reference. > > Support that case by using devm_regulator_get_optional(), and simply > hardcode the 2500000 uV in ad74413r_get_output_current_scale(). > > I'm not sure this is completely correct, but it's certainly better > than the current behaviour, where when refin-supply is not defined in > device tree, the regulator framework helpfully does its > > supply refin not found, using dummy regulator You could reasonably assume that's a bug in the firmware.. See suggestions in reply to patch 2. Given external wiring is involved, I don't think we can assume absence of a regulator means that loop back is in place. We need to indicate that explicitly in the binding in some way. Jonathan > > thing. When we then do the regulator_get_voltage(), that dummy > regulator of course doesn't support that operation and thus returns > -22 (-EINVAL) which is used without being checked. > > Signed-off-by: Rasmus Villemoes > --- > drivers/iio/addac/ad74413r.c | 31 ++++++++++++++++++++----------- > 1 file changed, 20 insertions(+), 11 deletions(-) > > diff --git a/drivers/iio/addac/ad74413r.c b/drivers/iio/addac/ad74413r.c > index 37485be88a63..9f77d2f514de 100644 > --- a/drivers/iio/addac/ad74413r.c > +++ b/drivers/iio/addac/ad74413r.c > @@ -608,7 +608,10 @@ static int ad74413r_get_output_voltage_scale(struct ad74413r_state *st, > static int ad74413r_get_output_current_scale(struct ad74413r_state *st, > int *val, int *val2) > { > - *val = regulator_get_voltage(st->refin_reg); > + if (st->refin_reg) > + *val = regulator_get_voltage(st->refin_reg); > + else > + *val = 2500000; > *val2 = st->sense_resistor_ohms * AD74413R_DAC_CODE_MAX * 1000; > > return IIO_VAL_FRACTIONAL; > @@ -1313,19 +1316,25 @@ static int ad74413r_probe(struct spi_device *spi) > if (IS_ERR(st->regmap)) > return PTR_ERR(st->regmap); > > - st->refin_reg = devm_regulator_get(st->dev, "refin"); > - if (IS_ERR(st->refin_reg)) > - return dev_err_probe(st->dev, PTR_ERR(st->refin_reg), > - "Failed to get refin regulator\n"); > + st->refin_reg = devm_regulator_get_optional(st->dev, "refin"); > + if (IS_ERR(st->refin_reg)) { > + ret = PTR_ERR(st->refin_reg); > + if (ret != -ENODEV) > + return dev_err_probe(st->dev, ret, > + "Failed to get refin regulator\n"); > + st->refin_reg = NULL; > + } > > - ret = regulator_enable(st->refin_reg); > - if (ret) > - return ret; > + if (st->refin_reg) { > + ret = regulator_enable(st->refin_reg); > + if (ret) > + return ret; > > - ret = devm_add_action_or_reset(st->dev, ad74413r_regulator_disable, > + ret = devm_add_action_or_reset(st->dev, ad74413r_regulator_disable, > st->refin_reg); > - if (ret) > - return ret; > + if (ret) > + return ret; > + } > > st->sense_resistor_ohms = 100000000; > device_property_read_u32(st->dev, "shunt-resistor-micro-ohms",