Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp1138117imm; Sun, 2 Sep 2018 11:03:50 -0700 (PDT) X-Google-Smtp-Source: ANB0VdZ9JwHLu4svG5Bp42DXWfkKopAJSYOQ1UkOdbRgWSoq00DAQzHqIkYh2YwsVQU3FnSJ4x2O X-Received: by 2002:a62:6c42:: with SMTP id h63-v6mr16977677pfc.65.1535911430814; Sun, 02 Sep 2018 11:03:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535911430; cv=none; d=google.com; s=arc-20160816; b=rMB98tAnZy45NhwQmaY+h+2ng/d9hG2foXpb//l+9ZsDm//tE5lWJH+oIga2LinRI8 rMbg9m3cQJSzFjbWPl6a1nwAmGN+15jbHcYOTmFhfR6FYc70rGvFcaIB7SLpUWgbWWIg msJjwXysloc/HSf8WGCKbTZpZZMW6ATKapqO8SaTVGfmhceNb3aHabFvxjg+RSxmxv8p nfz6usknLaMwORTr2AcAge/dz/bHNm9LayiKp3yUJsMxfE1Xd9d7MM1ZgOdol8U0pLYg lfyslVOduQkkcRJ74NRADXzb6o3fTx+uhW4EPZemH//sdLZY0uWjMcGPj7FLzm9g/D2I U7lA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature:arc-authentication-results; bh=zcQQIjcXhUQLTDp/Nerw6b+SSEfeIF+GhtlX4EyDe34=; b=CnuzG3wFlNjAadiR6QNRfKM7ieT6pB1RFeBWFdNbJDCcz9+7HXmWVduFRNHEjXFoOV aBGy6yTqih9G7gILsa+q/Xkv53Rtu7tmexvfPF/Ko3Bk+ipmziUlYIPhX/ZGW4TKyRjL 5JFFP6rpfBShV0h7StvwaxWj062dztCFNAkFy8MtFlQ46KpKuWPFokALAkOwo5ooVEQk MCnBSbIswnP/vg/zTmvhagos+nU8EhgDRVWHfgE7Fcgn+02quPUixAtk/k/LJ1y+QOSe lPEV6/CoBUmLKs9nKEtIPkKsJbytHxkTFnBkuo2NFCO4TZXE8OG1Ie44AIx9tmVTiF2P aTeA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=tEXKH+Yh; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b1-v6si14250962pls.367.2018.09.02.11.03.34; Sun, 02 Sep 2018 11:03:50 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=tEXKH+Yh; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 S1727048AbeIBWS5 (ORCPT + 99 others); Sun, 2 Sep 2018 18:18:57 -0400 Received: from mail.kernel.org ([198.145.29.99]:51840 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726065AbeIBWS5 (ORCPT ); Sun, 2 Sep 2018 18:18:57 -0400 Received: from archlinux (unknown [176.12.107.132]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id C8C3020835; Sun, 2 Sep 2018 18:02:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1535911340; bh=NIprCD9qe6te+diqs9tREvaAVPD6+S+HiisV3O6kljg=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=tEXKH+YhiHwHPjpBbsXZaW88v3JbyyN5QOy8vGt8RAyr2T9YhwHUWTYhnhylRzJLt jzVXCx/qWDrifDkppSkHVzT75TCxblNrZKw/N1qmceizC3ZIEr1k59TRN95vRQguxW 8IA4v5CS7y8pvHAdWJk3Z2G1A0ZDmdEYdHYzwF0s= Date: Sun, 2 Sep 2018 19:02:14 +0100 From: Jonathan Cameron To: Stefan Popa Cc: , , , , , , , , Subject: Re: [PATCH] iio: dac: ad5758: Add support for hard reset Message-ID: <20180902190214.116f2160@archlinux> In-Reply-To: <1535554722-1094-1-git-send-email-stefan.popa@analog.com> References: <1535554722-1094-1-git-send-email-stefan.popa@analog.com> X-Mailer: Claws Mail 3.17.1 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 29 Aug 2018 17:58:42 +0300 Stefan Popa wrote: > The ad5758 has a hardware reset active low input pin. This patch adds a > devicetree entry for a reset GPIO and a new ad5758_reset() function. > During > initialization, it is checked if the reset property is specified and the > the GPIO is being asserted, therefore the device will become active. > > When the reset function is called, if the gpio_reset var is set, then > the > GPIO will be toggled, otherwise a software reset is performed. > > Signed-off-by: Stefan Popa Two minors inline. I'll tidy it up whilst applying. Applied to the togreg branch of iio.git and pushed out as testing for the autobuilders to play with it. I'm taking the view that the binding addition is very straight forward but happy to have input from the DT maintainers if they wish to give it! Thanks, Jonathan > --- > .../devicetree/bindings/iio/dac/ad5758.txt | 5 ++++ > drivers/iio/dac/ad5758.c | 27 ++++++++++++++++++++-- > 2 files changed, 30 insertions(+), 2 deletions(-) > > diff --git a/Documentation/devicetree/bindings/iio/dac/ad5758.txt b/Documentation/devicetree/bindings/iio/dac/ad5758.txt > index bba01a5..bbcd789 100644 > --- a/Documentation/devicetree/bindings/iio/dac/ad5758.txt > +++ b/Documentation/devicetree/bindings/iio/dac/ad5758.txt > @@ -50,6 +50,9 @@ Required properties: > > Optional properties: > > + - reset-gpios : GPIO spec for the RESET pin. If specified, it will be > + asserted during driver probe. There is a space at the start of the line above that shouldn't be there. Fixed up. > + > - adi,dc-dc-ilim-microamp: The dc-to-dc converter current limit > The following values are currently supported [uA]: > * 150000 > @@ -71,6 +74,8 @@ AD5758 Example: > spi-max-frequency = <1000000>; > spi-cpha; > > + reset-gpios = <&gpio 22 0>; > + > adi,dc-dc-mode = <2>; > adi,range-microvolt = <0 10000000>; > adi,dc-dc-ilim-microamp = <200000>; > diff --git a/drivers/iio/dac/ad5758.c b/drivers/iio/dac/ad5758.c > index bd36333..b5cc5bd 100644 > --- a/drivers/iio/dac/ad5758.c > +++ b/drivers/iio/dac/ad5758.c > @@ -12,6 +12,7 @@ > #include > #include > #include > +#include > > #include > #include > @@ -108,6 +109,7 @@ struct ad5758_range { > struct ad5758_state { > struct spi_device *spi; > struct mutex lock; > + struct gpio_desc *gpio_reset; > struct ad5758_range out_range; > unsigned int dc_dc_mode; > unsigned int dc_dc_ilim; > @@ -474,6 +476,22 @@ static int ad5758_internal_buffers_en(struct ad5758_state *st, bool enable) > AD5758_CAL_MEM_UNREFRESHED_MSK); > } > > +static int ad5758_reset(struct ad5758_state *st) > +{ > + if (st->gpio_reset) { > + gpiod_set_value(st->gpio_reset, 0); > + usleep_range(100, 1000); > + gpiod_set_value(st->gpio_reset, 1); This feels like an odd construct. I would bring the usleep_range and final return into this if block. > + } else { > + /* Perform a software reset */ > + return ad5758_soft_reset(st); > + } > + > + usleep_range(100, 1000); > + > + return 0; > +} > + > static int ad5758_reg_access(struct iio_dev *indio_dev, > unsigned int reg, > unsigned int writeval, > @@ -768,13 +786,18 @@ static int ad5758_init(struct ad5758_state *st) > { > int regval, ret; > > + st->gpio_reset = devm_gpiod_get_optional(&st->spi->dev, "reset", > + GPIOD_OUT_HIGH); > + if (IS_ERR(st->gpio_reset)) > + return PTR_ERR(st->gpio_reset); > + > /* Disable CRC checks */ > ret = ad5758_crc_disable(st); > if (ret < 0) > return ret; > > - /* Perform a software reset */ > - ret = ad5758_soft_reset(st); > + /* Perform a reset */ > + ret = ad5758_reset(st); > if (ret < 0) > return ret; >