Message ID | 20231121-dev-iio-backend-v1-4-6a3d542eba35@analog.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2b07:b0:403:3b70:6f57 with SMTP id io7csp520929vqb; Tue, 21 Nov 2023 02:19:01 -0800 (PST) X-Google-Smtp-Source: AGHT+IGiXAlG0jWSW4Z5wJcLPoOlsKbE8o+qmAhHinKePrN7EjOBsqIbZHrHdkUCw09BjRwWNkYM X-Received: by 2002:a17:90a:3f87:b0:27f:bd9e:5a15 with SMTP id m7-20020a17090a3f8700b0027fbd9e5a15mr9071503pjc.28.1700561941272; Tue, 21 Nov 2023 02:19:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700561941; cv=none; d=google.com; s=arc-20160816; b=cjEH6iIxvTVo+jhK+/VsMCjn0fzOe041qOwA/M/FyrYe/7TMFk7AA5pG1jnOWrgYm3 nncRMUggaWBl3li9vSDuebMzI+ZvpK/8ZpL/wfu9Ppmegr26zWXtzDCYDe2bzNON/0aY cq/BS7FpWzMhq10wwmTXQIVnA5J8S24fueVg3iB83RPNg1fo1ttZybKSRvu/O60/gdjC jJmWhHGyuPzRtGmw4vpVFNuHkP8pW9EVTMsZ06+Owp1+BI5+lWnXGE0GNrl5r2NUaIdS 1jDFdic00IMWv87FWEH84bHpmhppNkSnhY35zMJSUF8mcFkumaFT5mqKVR9ZLB0BFxXP dNvA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:reply-to:cc:to:in-reply-to:references:message-id :content-transfer-encoding:mime-version:subject:date:from :dkim-signature; bh=8JgsAoU3Rt2OVF5NQG/Ml9OxQMUNF6H72pTKb3a7DCg=; fh=phDggtdq/mZScnogaJFJfeRDE2XPpZpUuxL35p15uks=; b=VBxJaRuj4bmt+evKVVR6kgSRlX/i/nE/xu/H62H4VjoCzN/70Nr3j2YMibSaqwoKKx kv7w2ZNbkbByIv0KsAAceaJUz8mAUa+J4OKsFa5EBEcthv+deE8cmtLi4SFbaQGh1cE7 7aWsPKMLkRx05At0Xtz8k4JLSFPAFSZn2EKIrZTnZC0IHXKnhZSswQ/ltrsn6PCjZCXR jzWW47SpGvFv4+zyE1mH8Xxpf3ErYVUw9YeN7uRL3ehrGClA6CTBdJJ4m2aORvfO5B6c NcENVtJSl864RlVYnJ+hwmgAtf3QYr1HP+100LSniFIuhP8x1phWjPtt/67W0KgSSHN+ pPVA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=vBOT88LO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id pi16-20020a17090b1e5000b0027766994586si13293620pjb.71.2023.11.21.02.19.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Nov 2023 02:19:01 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=vBOT88LO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 9E18B8061406; Tue, 21 Nov 2023 02:17:38 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230256AbjKUKR3 (ORCPT <rfc822;ouuuleilei@gmail.com> + 99 others); Tue, 21 Nov 2023 05:17:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48322 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232572AbjKUKRX (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Tue, 21 Nov 2023 05:17:23 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E1E1812A for <linux-kernel@vger.kernel.org>; Tue, 21 Nov 2023 02:17:19 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPS id 5818BC433AB; Tue, 21 Nov 2023 10:17:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1700561839; bh=kR1P1qDaKkBJqKHxLcftCCQPOWdMTfwi8zlle0jyKqw=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=vBOT88LOE9Hs6UmC0GZ+CrcV2x6FG/SzD+X2lONoB3JvL2tlNzl3MHT8mw/pDFRT0 lh1dLjA+OWD6POGvUMs7WJ2D42DbnNDq3r3I4QMJlgCh9qf3knMAZVFQ4T/uLwxC5x TrmLPYloHLqJm29RRfg6hQTtscFYPBS6BJil/qawV7Nn2VYbAgd2W2ES3nOG1Bxf7y 03xIs0RPogPghut6UUi37ZmcJw//Km2lM9xesngRIKyagRWdSvXb5Ep14q4t74YJZ5 SH89jBFFCUSLXwfUQWPvtg2gNv3xNHYQXH+VexP+48HP0cZ8aNewkEiGrs08OGDClX eJ59TbPZu538w== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 469B0C5ACB3; Tue, 21 Nov 2023 10:17:19 +0000 (UTC) From: Nuno Sa via B4 Relay <devnull+nuno.sa.analog.com@kernel.org> Date: Tue, 21 Nov 2023 11:20:17 +0100 Subject: [PATCH 04/12] iio: adc: ad9467: fix reset gpio handling MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20231121-dev-iio-backend-v1-4-6a3d542eba35@analog.com> References: <20231121-dev-iio-backend-v1-0-6a3d542eba35@analog.com> In-Reply-To: <20231121-dev-iio-backend-v1-0-6a3d542eba35@analog.com> To: linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-iio@vger.kernel.org Cc: Olivier MOYSAN <olivier.moysan@foss.st.com>, Greg Kroah-Hartman <gregkh@linuxfoundation.org>, "Rafael J. Wysocki" <rafael@kernel.org>, Rob Herring <robh+dt@kernel.org>, Frank Rowand <frowand.list@gmail.com>, Jonathan Cameron <jic23@kernel.org>, Lars-Peter Clausen <lars@metafoo.de>, Michael Hennerich <Michael.Hennerich@analog.com>, Nuno Sa <nuno.sa@analog.com> X-Mailer: b4 0.12.4 X-Developer-Signature: v=1; a=ed25519-sha256; t=1700562016; l=2235; i=nuno.sa@analog.com; s=20231116; h=from:subject:message-id; bh=FvM763XbCHeFm7zY4qdHtyTPDglD207l1cPfXL+Oe8g=; b=P0PYKwMAq5iL7cSwivnC4VVCg/v4uxIFKKFnAFSJextBIv6XHP6HMK5EgXWqu3AOEsvidK4k8 XV1C7/S/fs3AY8OC0AcvsmPzFVQheDspuKVpvkfZ3R5cLdaYu3EndBB X-Developer-Key: i=nuno.sa@analog.com; a=ed25519; pk=3NQwYA013OUYZsmDFBf8rmyyr5iQlxV/9H4/Df83o1E= X-Endpoint-Received: by B4 Relay for nuno.sa@analog.com/20231116 with auth_id=100 X-Original-From: Nuno Sa <nuno.sa@analog.com> Reply-To: <nuno.sa@analog.com> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Tue, 21 Nov 2023 02:17:38 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783168438192374227 X-GMAIL-MSGID: 1783168438192374227 |
Series |
iio: add new backend framework
|
|
Commit Message
Nuno Sa via B4 Relay
Nov. 21, 2023, 10:20 a.m. UTC
From: Nuno Sa <nuno.sa@analog.com> The reset gpio was being requested with GPIOD_OUT_LOW which means, not asserted. Then it was being asserted but never de-asserted which means the devices was left in reset. Fix it by de-asserting the gpio. While at it, moved the handling to it's own function and dropped 'reset_gpio' from the 'struct ad9467_state' as we only need it during probe. On top of that, refactored things so that we now request the gpio asserted (i.e in reset) and then de-assert it. Fixes: ad6797120238 ("iio: adc: ad9467: add support AD9467 ADC") Signed-off-by: Nuno Sa <nuno.sa@analog.com> --- drivers/iio/adc/ad9467.c | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-)
Comments
On Tue, Nov 21, 2023 at 4:17 AM Nuno Sa via B4 Relay <devnull+nuno.sa.analog.com@kernel.org> wrote: > > From: Nuno Sa <nuno.sa@analog.com> > > The reset gpio was being requested with GPIOD_OUT_LOW which means, not > asserted. Then it was being asserted but never de-asserted which means > the devices was left in reset. Fix it by de-asserting the gpio. It could be helpful to update the devicetree bindings to state the expected active-high or active-low setting for this gpio so it is clear which state means asserted. > > While at it, moved the handling to it's own function and dropped > 'reset_gpio' from the 'struct ad9467_state' as we only need it during > probe. On top of that, refactored things so that we now request the gpio > asserted (i.e in reset) and then de-assert it. > > Fixes: ad6797120238 ("iio: adc: ad9467: add support AD9467 ADC") > Signed-off-by: Nuno Sa <nuno.sa@analog.com> > --- > drivers/iio/adc/ad9467.c | 33 ++++++++++++++++++++------------- > 1 file changed, 20 insertions(+), 13 deletions(-) > > diff --git a/drivers/iio/adc/ad9467.c b/drivers/iio/adc/ad9467.c > index 39eccc28debe..368ea57be117 100644 > --- a/drivers/iio/adc/ad9467.c > +++ b/drivers/iio/adc/ad9467.c > @@ -121,7 +121,6 @@ struct ad9467_state { > unsigned int output_mode; > > struct gpio_desc *pwrdown_gpio; > - struct gpio_desc *reset_gpio; > }; > > static int ad9467_spi_read(struct spi_device *spi, unsigned int reg) > @@ -378,6 +377,23 @@ static int ad9467_preenable_setup(struct adi_axi_adc_conv *conv) > return ad9467_outputmode_set(st->spi, st->output_mode); > } > > +static int ad9467_reset(struct device *dev) > +{ > + struct gpio_desc *gpio; > + > + gpio = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_HIGH); > + if (IS_ERR(gpio)) > + return PTR_ERR(gpio); > + if (!gpio) > + return 0; can be done in one test instead of 2: if (IS_ERR_OR_NULL(gpio)) return PTR_ERR_OR_ZERO(gpio); > + > + fsleep(1); > + gpiod_direction_output(gpio, 0); > + fsleep(10); Previous version was 10 milliseconds instead of 10 microseconds. Was this change intentional? If yes, it should be mentioned it in the commit message. > + > + return 0; > +} > + > static int ad9467_probe(struct spi_device *spi) > { > const struct ad9467_chip_info *info; > @@ -408,18 +424,9 @@ static int ad9467_probe(struct spi_device *spi) > if (IS_ERR(st->pwrdown_gpio)) > return PTR_ERR(st->pwrdown_gpio); > > - st->reset_gpio = devm_gpiod_get_optional(&spi->dev, "reset", > - GPIOD_OUT_LOW); > - if (IS_ERR(st->reset_gpio)) > - return PTR_ERR(st->reset_gpio); > - > - if (st->reset_gpio) { > - udelay(1); > - ret = gpiod_direction_output(st->reset_gpio, 1); > - if (ret) > - return ret; > - mdelay(10); > - } > + ret = ad9467_reset(&spi->dev); > + if (ret) > + return ret; > > conv->chip_info = &info->axi_adc_info; > > > -- > 2.42.1 > >
On Thu, 2023-11-30 at 15:41 -0600, David Lechner wrote: > On Tue, Nov 21, 2023 at 4:17 AM Nuno Sa via B4 Relay > <devnull+nuno.sa.analog.com@kernel.org> wrote: > > > > From: Nuno Sa <nuno.sa@analog.com> > > > > The reset gpio was being requested with GPIOD_OUT_LOW which means, not > > asserted. Then it was being asserted but never de-asserted which means > > the devices was left in reset. Fix it by de-asserting the gpio. > > It could be helpful to update the devicetree bindings to state the > expected active-high or active-low setting for this gpio so it is > clear which state means asserted. > You could state that the chip is active low but I don't see that change that important for now. Not sure if this is clear and maybe that's why your comment. GPIOD_OUT_HIGH has nothing to do with active high or low. It just means, "get me the pin in the asserted state". > > While at it, moved the handling to it's own function and dropped > > 'reset_gpio' from the 'struct ad9467_state' as we only need it during > > probe. On top of that, refactored things so that we now request the gpio > > asserted (i.e in reset) and then de-assert it. > > > > Fixes: ad6797120238 ("iio: adc: ad9467: add support AD9467 ADC") > > Signed-off-by: Nuno Sa <nuno.sa@analog.com> > > --- > > drivers/iio/adc/ad9467.c | 33 ++++++++++++++++++++------------- > > 1 file changed, 20 insertions(+), 13 deletions(-) > > > > diff --git a/drivers/iio/adc/ad9467.c b/drivers/iio/adc/ad9467.c > > index 39eccc28debe..368ea57be117 100644 > > --- a/drivers/iio/adc/ad9467.c > > +++ b/drivers/iio/adc/ad9467.c > > @@ -121,7 +121,6 @@ struct ad9467_state { > > unsigned int output_mode; > > > > struct gpio_desc *pwrdown_gpio; > > - struct gpio_desc *reset_gpio; > > }; > > > > static int ad9467_spi_read(struct spi_device *spi, unsigned int reg) > > @@ -378,6 +377,23 @@ static int ad9467_preenable_setup(struct adi_axi_adc_conv > > *conv) > > return ad9467_outputmode_set(st->spi, st->output_mode); > > } > > > > +static int ad9467_reset(struct device *dev) > > +{ > > + struct gpio_desc *gpio; > > + > > + gpio = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_HIGH); > > + if (IS_ERR(gpio)) > > + return PTR_ERR(gpio); > > + if (!gpio) > > + return 0; > > can be done in one test instead of 2: > > if (IS_ERR_OR_NULL(gpio)) > return PTR_ERR_OR_ZERO(gpio); > Yep, better that way... > > + > > + fsleep(1); > > + gpiod_direction_output(gpio, 0); > > + fsleep(10); > > Previous version was 10 milliseconds instead of 10 microseconds. Was > this change intentional? If yes, it should be mentioned it in the > commit message. Oh, good catch! Copy past thing with even realizing the differences in the arguments :face_palm: - Nuno Sá >
On Fri, Dec 1, 2023 at 2:47 AM Nuno Sá <noname.nuno@gmail.com> wrote: > > On Thu, 2023-11-30 at 15:41 -0600, David Lechner wrote: > > On Tue, Nov 21, 2023 at 4:17 AM Nuno Sa via B4 Relay > > <devnull+nuno.sa.analog.com@kernel.org> wrote: > > > > > > From: Nuno Sa <nuno.sa@analog.com> > > > > > > The reset gpio was being requested with GPIOD_OUT_LOW which means, not > > > asserted. Then it was being asserted but never de-asserted which means > > > the devices was left in reset. Fix it by de-asserting the gpio. > > > > It could be helpful to update the devicetree bindings to state the > > expected active-high or active-low setting for this gpio so it is > > clear which state means asserted. > > > > You could state that the chip is active low but I don't see that change that > important for now. Not sure if this is clear and maybe that's why your comment. > GPIOD_OUT_HIGH has nothing to do with active high or low. It just means, "get me the > pin in the asserted state". > I would assume that this bug happened in the first place because someone forgot GPIOD_OUT_LOW in the devicetree when they were developing the driver. So this is why I suggested that updating the devicetree binding docs so that future users are less likely to make the same mistake. Currently, the bindings don't even have reset-gpios in the examples.
On Fri, 2023-12-01 at 11:01 -0600, David Lechner wrote: > On Fri, Dec 1, 2023 at 2:47 AM Nuno Sá <noname.nuno@gmail.com> wrote: > > > > On Thu, 2023-11-30 at 15:41 -0600, David Lechner wrote: > > > On Tue, Nov 21, 2023 at 4:17 AM Nuno Sa via B4 Relay > > > <devnull+nuno.sa.analog.com@kernel.org> wrote: > > > > > > > > From: Nuno Sa <nuno.sa@analog.com> > > > > > > > > The reset gpio was being requested with GPIOD_OUT_LOW which means, not > > > > asserted. Then it was being asserted but never de-asserted which means > > > > the devices was left in reset. Fix it by de-asserting the gpio. > > > > > > It could be helpful to update the devicetree bindings to state the > > > expected active-high or active-low setting for this gpio so it is > > > clear which state means asserted. > > > > > > > You could state that the chip is active low but I don't see that change that > > important for now. Not sure if this is clear and maybe that's why your comment. > > GPIOD_OUT_HIGH has nothing to do with active high or low. It just means, "get me > > the > > pin in the asserted state". > > > > I would assume that this bug happened in the first place because > someone forgot GPIOD_OUT_LOW in the devicetree when they were > developing the driver. So this is why I suggested that updating the > devicetree binding docs so that future users are less likely to make > the same mistake. Currently, the bindings don't even have reset-gpios > in the examples. Hmm, I think you're missing the point... The bug has nothing to do with devicetree. This is what was happening: 1) We were calling devm_gpiod_get_optional() with GPIOD_OUT_LOW. What this means is that you get an output gpio deasserted. Hence the device is out of reset. And here is the important part... what you have in dts does not matter. If you have active low, it means the pin level will be 1. If you have high, the pin level is 0. And this is all handled by gpiolib for you. 2) Then, we called gpiod_direction_output(..., 1), which means set the direction out (which is actually not needed since it was already done when getting the pin) and assert the pin. Hence, reset the device. And we were never de-asserting the pin so the device would be left in reset. - Nuno Sá
On Sat, 02 Dec 2023 09:36:47 +0100 Nuno Sá <noname.nuno@gmail.com> wrote: > On Fri, 2023-12-01 at 11:01 -0600, David Lechner wrote: > > On Fri, Dec 1, 2023 at 2:47 AM Nuno Sá <noname.nuno@gmail.com> wrote: > > > > > > On Thu, 2023-11-30 at 15:41 -0600, David Lechner wrote: > > > > On Tue, Nov 21, 2023 at 4:17 AM Nuno Sa via B4 Relay > > > > <devnull+nuno.sa.analog.com@kernel.org> wrote: > > > > > > > > > > From: Nuno Sa <nuno.sa@analog.com> > > > > > > > > > > The reset gpio was being requested with GPIOD_OUT_LOW which means, not > > > > > asserted. Then it was being asserted but never de-asserted which means > > > > > the devices was left in reset. Fix it by de-asserting the gpio. > > > > > > > > It could be helpful to update the devicetree bindings to state the > > > > expected active-high or active-low setting for this gpio so it is > > > > clear which state means asserted. > > > > > > > > > > You could state that the chip is active low but I don't see that change that > > > important for now. Not sure if this is clear and maybe that's why your comment. > > > GPIOD_OUT_HIGH has nothing to do with active high or low. It just means, "get me > > > the > > > pin in the asserted state". > > > > > > > I would assume that this bug happened in the first place because > > someone forgot GPIOD_OUT_LOW in the devicetree when they were > > developing the driver. So this is why I suggested that updating the > > devicetree binding docs so that future users are less likely to make > > the same mistake. Currently, the bindings don't even have reset-gpios > > in the examples. > > Hmm, I think you're missing the point... The bug has nothing to do with devicetree. > This is what was happening: > > 1) We were calling devm_gpiod_get_optional() with GPIOD_OUT_LOW. What this means is > that you get an output gpio deasserted. Hence the device is out of reset. And here is > the important part... what you have in dts does not matter. If you have active low, > it means the pin level will be 1. If you have high, the pin level is 0. And this is > all handled by gpiolib for you. > > 2) Then, we called gpiod_direction_output(..., 1), which means set the direction out > (which is actually not needed since it was already done when getting the pin) and > assert the pin. Hence, reset the device. And we were never de-asserting the pin so > the device would be left in reset. Functionally I believe David is correct. Flipping the DT would 'fix' this. It's all down to a nreset vs reset pin description. In this case I guess it's defined a a 'not reset' on the datasheet which is what is causing the confusion. It's not uncommon for people to refer to a reset when they mean a "not reset" with assumptions on polarity to match. Jonathan > > - Nuno Sá
On Mon, 2023-12-04 at 15:15 +0000, Jonathan Cameron wrote: > On Sat, 02 Dec 2023 09:36:47 +0100 > Nuno Sá <noname.nuno@gmail.com> wrote: > > > On Fri, 2023-12-01 at 11:01 -0600, David Lechner wrote: > > > On Fri, Dec 1, 2023 at 2:47 AM Nuno Sá <noname.nuno@gmail.com> wrote: > > > > > > > > On Thu, 2023-11-30 at 15:41 -0600, David Lechner wrote: > > > > > On Tue, Nov 21, 2023 at 4:17 AM Nuno Sa via B4 Relay > > > > > <devnull+nuno.sa.analog.com@kernel.org> wrote: > > > > > > > > > > > > From: Nuno Sa <nuno.sa@analog.com> > > > > > > > > > > > > The reset gpio was being requested with GPIOD_OUT_LOW which means, not > > > > > > asserted. Then it was being asserted but never de-asserted which means > > > > > > the devices was left in reset. Fix it by de-asserting the gpio. > > > > > > > > > > It could be helpful to update the devicetree bindings to state the > > > > > expected active-high or active-low setting for this gpio so it is > > > > > clear which state means asserted. > > > > > > > > > > > > > You could state that the chip is active low but I don't see that change that > > > > important for now. Not sure if this is clear and maybe that's why your > > > > comment. > > > > GPIOD_OUT_HIGH has nothing to do with active high or low. It just means, "get > > > > me > > > > the > > > > pin in the asserted state". > > > > > > > > > > I would assume that this bug happened in the first place because > > > someone forgot GPIOD_OUT_LOW in the devicetree when they were > > > developing the driver. So this is why I suggested that updating the > > > devicetree binding docs so that future users are less likely to make > > > the same mistake. Currently, the bindings don't even have reset-gpios > > > in the examples. > > > > Hmm, I think you're missing the point... The bug has nothing to do with > > devicetree. > > This is what was happening: > > > > 1) We were calling devm_gpiod_get_optional() with GPIOD_OUT_LOW. What this means > > is > > that you get an output gpio deasserted. Hence the device is out of reset. And > > here is > > the important part... what you have in dts does not matter. If you have active > > low, > > it means the pin level will be 1. If you have high, the pin level is 0. And this > > is > > all handled by gpiolib for you. > > > > 2) Then, we called gpiod_direction_output(..., 1), which means set the direction > > out > > (which is actually not needed since it was already done when getting the pin) and > > assert the pin. Hence, reset the device. And we were never de-asserting the pin > > so > > the device would be left in reset. > > Functionally I believe David is correct. Flipping the DT would 'fix' this. > It's all down to a nreset vs reset pin description. > Ahh I see. Well would not really be a fix :) - Nuno Sá
diff --git a/drivers/iio/adc/ad9467.c b/drivers/iio/adc/ad9467.c index 39eccc28debe..368ea57be117 100644 --- a/drivers/iio/adc/ad9467.c +++ b/drivers/iio/adc/ad9467.c @@ -121,7 +121,6 @@ struct ad9467_state { unsigned int output_mode; struct gpio_desc *pwrdown_gpio; - struct gpio_desc *reset_gpio; }; static int ad9467_spi_read(struct spi_device *spi, unsigned int reg) @@ -378,6 +377,23 @@ static int ad9467_preenable_setup(struct adi_axi_adc_conv *conv) return ad9467_outputmode_set(st->spi, st->output_mode); } +static int ad9467_reset(struct device *dev) +{ + struct gpio_desc *gpio; + + gpio = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_HIGH); + if (IS_ERR(gpio)) + return PTR_ERR(gpio); + if (!gpio) + return 0; + + fsleep(1); + gpiod_direction_output(gpio, 0); + fsleep(10); + + return 0; +} + static int ad9467_probe(struct spi_device *spi) { const struct ad9467_chip_info *info; @@ -408,18 +424,9 @@ static int ad9467_probe(struct spi_device *spi) if (IS_ERR(st->pwrdown_gpio)) return PTR_ERR(st->pwrdown_gpio); - st->reset_gpio = devm_gpiod_get_optional(&spi->dev, "reset", - GPIOD_OUT_LOW); - if (IS_ERR(st->reset_gpio)) - return PTR_ERR(st->reset_gpio); - - if (st->reset_gpio) { - udelay(1); - ret = gpiod_direction_output(st->reset_gpio, 1); - if (ret) - return ret; - mdelay(10); - } + ret = ad9467_reset(&spi->dev); + if (ret) + return ret; conv->chip_info = &info->axi_adc_info;