From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7B60FC433EF for ; Thu, 9 Sep 2021 13:26:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 588ED61101 for ; Thu, 9 Sep 2021 13:26:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1356284AbhIIN1k (ORCPT ); Thu, 9 Sep 2021 09:27:40 -0400 Received: from mail.kernel.org ([198.145.29.99]:35404 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1358489AbhIINLR (ORCPT ); Thu, 9 Sep 2021 09:11:17 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 0DAE161501; Thu, 9 Sep 2021 12:01:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1631188880; bh=SY6y8U71EGd4aHjByJyQV570JiwGzg0mb0VxOk/josg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qVWXli0qiWWnoZf/apDvKbvj4UAxoCxAWaXRJ9FNSXAi8mTN5MhoNXloXIHxC6x86 YL6Iq0oahGEmqxCu2A8AkmF1eP9oEYymQXK9VHwXhOU8DkzMloCWmUpH0bw9G/diY7 +cVRCXfM9z3ckCRNsvVWMBt3d2Ud1c/s7A3UrdYMiLffgXoxX8z+B6v9E+miTkjW/Y Qw61rrG1rIoWJfO6kL1ncFRNkfoezrYT8MMuEswGVoyt7G/5Cmag6uZUW626xDksbK kESsbF/jvNMNwbCpYEJ7qUYChEDzN2nTxdgp3Td/n3w60+5+uXuppqHyK0UZY4FdLl ECMbcucW2p84w== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Jonathan Cameron , kernel test robot , =?UTF-8?q?Nuno=20S=C3=A1?= , Sasha Levin , linux-iio@vger.kernel.org Subject: [PATCH AUTOSEL 4.4 03/35] iio: dac: ad5624r: Fix incorrect handling of an optional regulator. Date: Thu, 9 Sep 2021 08:00:44 -0400 Message-Id: <20210909120116.150912-3-sashal@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210909120116.150912-1-sashal@kernel.org> References: <20210909120116.150912-1-sashal@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jonathan Cameron [ Upstream commit 97683c851f9cdbd3ea55697cbe2dcb6af4287bbd ] The naming of the regulator is problematic. VCC is usually a supply voltage whereas these devices have a separate VREF pin. Secondly, the regulator core might have provided a stub regulator if a real regulator wasn't provided. That would in turn have failed to provide a voltage when queried. So reality was that there was no way to use the internal reference. In order to avoid breaking any dts out in the wild, make sure to fallback to the original vcc naming if vref is not available. Signed-off-by: Jonathan Cameron Reported-by: kernel test robot Acked-by: Nuno Sá Link: https://lore.kernel.org/r/20210627163244.1090296-9-jic23@kernel.org Signed-off-by: Sasha Levin --- drivers/iio/dac/ad5624r_spi.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/drivers/iio/dac/ad5624r_spi.c b/drivers/iio/dac/ad5624r_spi.c index 5489ec43b95d..e5cefdb674f8 100644 --- a/drivers/iio/dac/ad5624r_spi.c +++ b/drivers/iio/dac/ad5624r_spi.c @@ -231,7 +231,7 @@ static int ad5624r_probe(struct spi_device *spi) if (!indio_dev) return -ENOMEM; st = iio_priv(indio_dev); - st->reg = devm_regulator_get(&spi->dev, "vcc"); + st->reg = devm_regulator_get_optional(&spi->dev, "vref"); if (!IS_ERR(st->reg)) { ret = regulator_enable(st->reg); if (ret) @@ -242,6 +242,22 @@ static int ad5624r_probe(struct spi_device *spi) goto error_disable_reg; voltage_uv = ret; + } else { + if (PTR_ERR(st->reg) != -ENODEV) + return PTR_ERR(st->reg); + /* Backwards compatibility. This naming is not correct */ + st->reg = devm_regulator_get_optional(&spi->dev, "vcc"); + if (!IS_ERR(st->reg)) { + ret = regulator_enable(st->reg); + if (ret) + return ret; + + ret = regulator_get_voltage(st->reg); + if (ret < 0) + goto error_disable_reg; + + voltage_uv = ret; + } } spi_set_drvdata(spi, indio_dev); -- 2.30.2