Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp1147399rwl; Fri, 7 Apr 2023 10:36:58 -0700 (PDT) X-Google-Smtp-Source: AKy350ZNEbBZejr9+GroMAMOQqnn7v7PCy2GKniXu9k2qFoLW6SFyYF8C/gjkU6vXS/cAlketif0 X-Received: by 2002:a17:902:e5ca:b0:19f:2dff:2199 with SMTP id u10-20020a170902e5ca00b0019f2dff2199mr4481134plf.68.1680889018114; Fri, 07 Apr 2023 10:36:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680889018; cv=none; d=google.com; s=arc-20160816; b=p6pXnGkv6OnBn5+NOee6/y7xIuyLRX2UZ60tgGMhOV9uAQqhP3Bk5JOJWqmcEW0n/y bEYm4Ya/XBj2nzVDXTsxWzrI45CQXIXj7q2sjIFKJtxia4mFnSwKEl0Z9fSWKJ/uw+Qo avoKuxjq68v0GRTK61UpYil3K00flOQL7UtCL2MrZvJZO4KCbwpTbLdNJHgWHO0DpeSE TLLkYgkVsESdV4Wr4Osvoce6NSgaa0Dd0gwzMXgXg4wNC8MgEi2PEg+BNqouNDAJsIem MCGCgXBM5rRlZlEoTGt2Jxe4zO5H/9Mwlvd1lkZ0mBa9pBWeoFonL7/loerjJfW0Omf1 tEOA== 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=vO4S2g7+Pa9XTLKqh9GaZKH98/QVLb5XukwSnQh8YsU=; b=Ct2Yqgfjs9A2CiE61QtUb8vJ4k65lZRIKkvSp2unHuXBU7Bac2rRBRxvveSpsRjvNq UUkgy5raSE5rF2i/C3iD5xIJnmnJWhKU0RRlpRleE16+T8jRjf+ByW98Qo8TKC6b/uuY aDhOWeZVgH4mdJ/JwAwgsJO5QAGXRUELG+6UFbBlJrMche79xmV+TZveTq5G4dKBAx1n PHeDbwUaGvdNMLv90PmApnxZd23gkkYPcF8jbedruO57Txuj3g+w8do0vddsDNqou96V n/RiCEfC6ifqpD/U3IVOB1biasHUO6Sb5bPde7pOSCNarqESF0zAWl/WdkHR7W0rsXIc 7AdA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="Rd/h7Gqi"; 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 y72-20020a638a4b000000b0050beb3fe616si3919116pgd.462.2023.04.07.10.36.46; Fri, 07 Apr 2023 10:36:58 -0700 (PDT) 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="Rd/h7Gqi"; 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 S229586AbjDGR3H (ORCPT + 99 others); Fri, 7 Apr 2023 13:29:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34280 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229446AbjDGR3G (ORCPT ); Fri, 7 Apr 2023 13:29:06 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0D9D1A5FA; Fri, 7 Apr 2023 10:29:05 -0700 (PDT) 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 dfw.source.kernel.org (Postfix) with ESMTPS id 9BACF6522F; Fri, 7 Apr 2023 17:29:04 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3DC2CC433EF; Fri, 7 Apr 2023 17:29:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1680888544; bh=HM8yc0g7zGvNrkwC2ClMGSBe7mAsX0QqDan2d5P6KwY=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=Rd/h7GqijfTNutX8NAo+CaMU+YWQ1znP5am7XaLwcvHwBjwp65GehhJpoeBLMo9iT IoRsGhuBJnpH7OOruHRJqz+yon7jcUhgXG51r0kNxVthRwCiVx40u8s2l37kPefVrJ 8e05txpqmETRLafFloQJmCDjzBJLYgizstLIqxUiZb9BNjrTIRPPQ5nyvvlpWD5ZKX K94moDNpTMTUN8oM8ivZdZgXiYDmHq2HWj1NOh141VCBL/moDD4JyO5y106xI09p93 3YkfTCfy8P5fwFqNh2dIHzavvdfgW5WfUDjlZRel+Owl6YyXjZHch0XuqUdI7U/F29 7uO2ZIVSCY+EA== Date: Fri, 7 Apr 2023 18:44:20 +0100 From: Jonathan Cameron To: Nicolas Frattaroli Cc: Lars-Peter Clausen , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 2/4] iio: dac: mcp4922: get and enable vdd regulator Message-ID: <20230407184420.1cd54af0@jic23-huawei> In-Reply-To: <20230405140114.99011-3-frattaroli.nicolas@gmail.com> References: <20230405140114.99011-1-frattaroli.nicolas@gmail.com> <20230405140114.99011-3-frattaroli.nicolas@gmail.com> X-Mailer: Claws Mail 4.1.1 (GTK 3.24.37; 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=-5.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI,SPF_HELO_NONE, SPF_PASS autolearn=unavailable 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 Wed, 5 Apr 2023 16:01:12 +0200 Nicolas Frattaroli wrote: > The MCP4922 family of chips has a vdd power input, which we > model in our device tree binding for it. The driver should get > and enable the vdd regulator as is appropriate. > > Signed-off-by: Nicolas Frattaroli If, before doing this you add a patch using devm for all the unwinding currently being done by hand in remove() you can simplify this further use devm_regulator_get_enable() (Note you can only do that for this regulator as we never touch it after enable - more complex handling needed for the vref one as described in review of patch 4.) That conversion patch is pretty simple, so whilst I don't like asking people to implement extra features, in this case the simplifications to what you are doing here make that precusor work justified Jonathan > --- > drivers/iio/dac/mcp4922.c | 24 ++++++++++++++++++++---- > 1 file changed, 20 insertions(+), 4 deletions(-) > > diff --git a/drivers/iio/dac/mcp4922.c b/drivers/iio/dac/mcp4922.c > index da4327624d45..0b9458cbbcff 100644 > --- a/drivers/iio/dac/mcp4922.c > +++ b/drivers/iio/dac/mcp4922.c > @@ -31,6 +31,7 @@ struct mcp4922_state { > unsigned int value[MCP4922_NUM_CHANNELS]; > unsigned int vref_mv; > struct regulator *vref_reg; > + struct regulator *vdd_reg; > u8 mosi[2] __aligned(IIO_DMA_MINALIGN); > }; > > @@ -148,10 +149,23 @@ static int mcp4922_probe(struct spi_device *spi) > if (ret < 0) { > dev_err(&spi->dev, "Failed to read vref regulator: %d\n", > ret); > - goto error_disable_reg; > + goto error_disable_vref_reg; > } > state->vref_mv = ret / 1000; > > + state->vdd_reg = devm_regulator_get(&spi->dev, "vdd"); > + if (IS_ERR(state->vdd_reg)) { > + ret = dev_err_probe(&spi->dev, PTR_ERR(state->vdd_reg), > + "vdd regulator not specified\n"); > + goto error_disable_vref_reg; > + } > + ret = regulator_enable(state->vdd_reg); > + if (ret) { > + dev_err(&spi->dev, "Failed to enable vdd regulator: %d\n", > + ret); > + goto error_disable_vref_reg; > + } > + > spi_set_drvdata(spi, indio_dev); > id = spi_get_device_id(spi); > indio_dev->info = &mcp4922_info; > @@ -167,12 +181,13 @@ static int mcp4922_probe(struct spi_device *spi) > if (ret) { > dev_err(&spi->dev, "Failed to register iio device: %d\n", > ret); > - goto error_disable_reg; > + goto error_disable_vdd_reg; > } > > return 0; > - > -error_disable_reg: > +error_disable_vdd_reg: > + regulator_disable(state->vdd_reg); > +error_disable_vref_reg: > regulator_disable(state->vref_reg); > > return ret; > @@ -185,6 +200,7 @@ static void mcp4922_remove(struct spi_device *spi) > > iio_device_unregister(indio_dev); > state = iio_priv(indio_dev); > + regulator_disable(state->vdd_reg); > regulator_disable(state->vref_reg); > } >