From patchwork Tue May 11 07:18:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandru Ardelean X-Patchwork-Id: 12249959 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=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham 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 2C0FEC43461 for ; Tue, 11 May 2021 07:18:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id F06D66187E for ; Tue, 11 May 2021 07:18:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230366AbhEKHTp (ORCPT ); Tue, 11 May 2021 03:19:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35784 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230332AbhEKHTn (ORCPT ); Tue, 11 May 2021 03:19:43 -0400 Received: from mail-ej1-x62f.google.com (mail-ej1-x62f.google.com [IPv6:2a00:1450:4864:20::62f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C2AA2C06175F for ; Tue, 11 May 2021 00:18:37 -0700 (PDT) Received: by mail-ej1-x62f.google.com with SMTP id j10so1178388ejb.3 for ; Tue, 11 May 2021 00:18:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=deviqon.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=URnNCU/Gt3uzfVjqFnT5ZArbKyWbTbXjKVLfJMYugCE=; b=JSOSsYmFD5QmGgpDLNRQitF/l6W3zvsTNv8c9WmaXd2ytjXpPNKnrjA//1MXHMKdUE Azc38GcVttcldRR6C6uCuQd2x6ZjxIxzuxcSSJMhU8pbgnHZ9MGYrd9yUNMqow+IZagb LT9r9GzcLMwU6sFdCxUTMDbTO6uHpv39PGp4dg1sblqjLxDOaKUJavNbNu5+BIVvT8Y+ gWWx3jnc+18uzkjZNZSWQBLI8/KNV1W/iP5/NJfPk1vNytiHBIv47S7Ndkaca5c4uCRf XBdptlEmuOM1mbo/G2Uj6lolKHyn0b08u8QUgkE7bk8W7yaIMDVrWWDo+DvGeG8hb3Lm Zivw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=URnNCU/Gt3uzfVjqFnT5ZArbKyWbTbXjKVLfJMYugCE=; b=nBeAFzddsFcWt6Mj8gPpkULC7QKqjqi+vQBTiMgAnBbYkJ16iXK2wB/PAtirkIhYB9 DKR0xdGqhUJ1rCiMHyJ5ty3AMg7eiXj9h1xqh0j0gqtBA2Ty+NzVNDP/F3Macbh0jmGo kO1sgDPKm9JPyo7xaEZVpxwXcq86XSWje1Cg3dHy1xPcRqTQ5B1tJKKO6TzGlmkL0IZj W6KvyTR+aUoMN2npqhJ+ccNM5nchYhLdWxzQSjZZ8JQAANO7plIKaibEntYOrYX3RZKO dErw4ObiG3+Rkyeg5K6u2sQD1EH8EBETYnaiDI0x2nJ1TfHFNkgiiXPNBydAWvuomZUx rgqg== X-Gm-Message-State: AOAM533w2+1xMgW3G5lB+Mg/hDZhgQFmx6bLEmp8iELFfFs0RYZ/C65K F107CnigbAw/any9Yyt55yIQEgptkKTGFpQL X-Google-Smtp-Source: ABdhPJzy+HvcxMAOOjEm/Ok25x2DCeZ+Ccd5ehFBwVZpAP2ETTvbrN8ygknq/Ttld5JGtMxROYL/1Q== X-Received: by 2002:a17:906:1e0b:: with SMTP id g11mr29707544ejj.291.1620717516331; Tue, 11 May 2021 00:18:36 -0700 (PDT) Received: from neptune.. ([188.27.131.122]) by smtp.gmail.com with ESMTPSA id i6sm13871558eds.83.2021.05.11.00.18.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 May 2021 00:18:36 -0700 (PDT) From: Alexandru Ardelean To: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Cc: jic23@kernel.org, Jonathan.Cameron@huawei.com, alexandru.tachici@analog.com, linux@deviqon.com, Alexandru Ardelean , Alexandru Ardelean Subject: [PATCH v2 01/12] iio: adc: ad7124: Fix missbalanced regulator enable / disable on error. Date: Tue, 11 May 2021 10:18:20 +0300 Message-Id: <20210511071831.576145-2-aardelean@deviqon.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210511071831.576145-1-aardelean@deviqon.com> References: <20210511071831.576145-1-aardelean@deviqon.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org From: Jonathan Cameron If the devm_regulator_get() call succeeded but not the regulator_enable() then regulator_disable() would be called on a regulator that was not enabled. Fix this by moving regulator enabling / disabling over to devm_ management via devm_add_action_or_reset. Fixes: b3af341bbd96 ("iio: adc: Add ad7124 support") Reviewed-by: Alexandru Ardelean Signed-off-by: Jonathan Cameron Signed-off-by: Alexandru Ardelean --- drivers/iio/adc/ad7124.c | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/drivers/iio/adc/ad7124.c b/drivers/iio/adc/ad7124.c index 9d3952b4674f..437116a07cf1 100644 --- a/drivers/iio/adc/ad7124.c +++ b/drivers/iio/adc/ad7124.c @@ -850,6 +850,11 @@ static int ad7124_setup(struct ad7124_state *st) return ret; } +static void ad7124_reg_disable(void *r) +{ + regulator_disable(r); +} + static int ad7124_probe(struct spi_device *spi) { const struct ad7124_chip_info *info; @@ -895,17 +900,20 @@ static int ad7124_probe(struct spi_device *spi) ret = regulator_enable(st->vref[i]); if (ret) return ret; + + ret = devm_add_action_or_reset(&spi->dev, ad7124_reg_disable, + st->vref[i]); + if (ret) + return ret; } st->mclk = devm_clk_get(&spi->dev, "mclk"); - if (IS_ERR(st->mclk)) { - ret = PTR_ERR(st->mclk); - goto error_regulator_disable; - } + if (IS_ERR(st->mclk)) + return PTR_ERR(st->mclk); ret = clk_prepare_enable(st->mclk); if (ret < 0) - goto error_regulator_disable; + return ret; ret = ad7124_soft_reset(st); if (ret < 0) @@ -935,11 +943,6 @@ static int ad7124_probe(struct spi_device *spi) ad_sd_cleanup_buffer_and_trigger(indio_dev); error_clk_disable_unprepare: clk_disable_unprepare(st->mclk); -error_regulator_disable: - for (i = ARRAY_SIZE(st->vref) - 1; i >= 0; i--) { - if (!IS_ERR_OR_NULL(st->vref[i])) - regulator_disable(st->vref[i]); - } return ret; } @@ -948,17 +951,11 @@ static int ad7124_remove(struct spi_device *spi) { struct iio_dev *indio_dev = spi_get_drvdata(spi); struct ad7124_state *st = iio_priv(indio_dev); - int i; iio_device_unregister(indio_dev); ad_sd_cleanup_buffer_and_trigger(indio_dev); clk_disable_unprepare(st->mclk); - for (i = ARRAY_SIZE(st->vref) - 1; i >= 0; i--) { - if (!IS_ERR_OR_NULL(st->vref[i])) - regulator_disable(st->vref[i]); - } - return 0; } From patchwork Tue May 11 07:18:21 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandru Ardelean X-Patchwork-Id: 12249961 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=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham 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 2F6C2C43460 for ; Tue, 11 May 2021 07:18:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id F08DF6187E for ; Tue, 11 May 2021 07:18:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230430AbhEKHTq (ORCPT ); Tue, 11 May 2021 03:19:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35796 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230387AbhEKHTp (ORCPT ); Tue, 11 May 2021 03:19:45 -0400 Received: from mail-ej1-x634.google.com (mail-ej1-x634.google.com [IPv6:2a00:1450:4864:20::634]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BE48CC06175F for ; Tue, 11 May 2021 00:18:38 -0700 (PDT) Received: by mail-ej1-x634.google.com with SMTP id j10so1178439ejb.3 for ; Tue, 11 May 2021 00:18:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=deviqon.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=MlVahHcRzJl/OmCKvY8N8NXLgxaRCwf7xRO5a1v6DG4=; b=BtT9If2o8biK/TQo2D8iH5bLbUNr2OSpCmPrMkG7+9NX0wPnU577xaNxF6GxpWPkOT WcKmoisQKH7iGLvW+j2yD81ooRu/VTCEhGr/WKvQjpREbjgAQvalT9/lo1e6DxHwruW9 JwUH9rcmjoEv4hANcCcOj/Pi2fEJjHICQISZ0bOX7RJO2Ydnp+zhGoHwjNGhZUdLfX7u G6EHOORr98nJSTWOj2OT+TjSgqD3kLDlfGpDmEf9QKjk02vacPFrNKsL2nguL2ZvSThb SJeKYo34GoQcDorGwmJvL1CUz2mMoBdtITAoUEud3dPiF1rnhXqDNIag/X5TuDeKKRWN 7YfA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=MlVahHcRzJl/OmCKvY8N8NXLgxaRCwf7xRO5a1v6DG4=; b=uZA6M6Z5aNsIlfXmt35W/QhrBllagRnU4j5H/fpIdEOdzj+N4Dh8I/Iv/rNI8r2ikM KKmfyoXLd/GiZkrQnt624J6Unz3a9l8VynIiX7+lPCUpLYBbJOfLgZCsLGfApxF5frXE afi3x2uW67clxGIBq2wK9jU+z8i81pL5oJKKfhzI1Zns3FUq5n4hrdtAl0y+mK4uDlOO B4YVdBO1hTT4zFdQG396BVZDVDkSIR10cKbsG84hUsFnRul2CRS0yH/25uTTpWUaVGDk vPeubM888MwsxrCNiUqCgHepKIpBDxzooiqKxi6QpXl6Y+bVRRm55Bj2c+CgfPH9wPrT AbZA== X-Gm-Message-State: AOAM5311u0tBqKJ/eVakz3ntPg7ZsuAMVMKijHJchuiPFZ9KrRRYrT49 9wyuEKvDn1yZJKT4GaWC8qdHVot0grdD3Cwp X-Google-Smtp-Source: ABdhPJzZng0DRdVx9nvvyxFhc+bf78j3QPK4vbwrrKHyqn36fRx84GO3udQzPeta72P+WJJt7+gWaQ== X-Received: by 2002:a17:906:2da1:: with SMTP id g1mr30189831eji.47.1620717517277; Tue, 11 May 2021 00:18:37 -0700 (PDT) Received: from neptune.. ([188.27.131.122]) by smtp.gmail.com with ESMTPSA id i6sm13871558eds.83.2021.05.11.00.18.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 May 2021 00:18:37 -0700 (PDT) From: Alexandru Ardelean To: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Cc: jic23@kernel.org, Jonathan.Cameron@huawei.com, alexandru.tachici@analog.com, linux@deviqon.com, Alexandru Ardelean , Alexandru Ardelean Subject: [PATCH v2 02/12] iio: adc: ad7124: Fix potential overflow due to non sequential channel numbers Date: Tue, 11 May 2021 10:18:21 +0300 Message-Id: <20210511071831.576145-3-aardelean@deviqon.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210511071831.576145-1-aardelean@deviqon.com> References: <20210511071831.576145-1-aardelean@deviqon.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org From: Jonathan Cameron Channel numbering must start at 0 and then not have any holes, or it is possible to overflow the available storage. Note this bug was introduced as part of a fix to ensure we didn't rely on the ordering of child nodes. So we need to support arbitrary ordering but they all need to be there somewhere. Note I hit this when using qemu to test the rest of this series. Arguably this isn't the best fix, but it is probably the most minimal option for backporting etc. Fixes: d7857e4ee1ba6 ("iio: adc: ad7124: Fix DT channel configuration") Reviewed-by: Alexandru Ardelean Signed-off-by: Jonathan Cameron Signed-off-by: Alexandru Ardelean --- drivers/iio/adc/ad7124.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/drivers/iio/adc/ad7124.c b/drivers/iio/adc/ad7124.c index 437116a07cf1..a27db78ea13e 100644 --- a/drivers/iio/adc/ad7124.c +++ b/drivers/iio/adc/ad7124.c @@ -771,6 +771,13 @@ static int ad7124_of_parse_channel_config(struct iio_dev *indio_dev, if (ret) goto err; + if (channel >= indio_dev->num_channels) { + dev_err(indio_dev->dev.parent, + "Channel index >= number of channels\n"); + ret = -EINVAL; + goto err; + } + ret = of_property_read_u32_array(child, "diff-channels", ain, 2); if (ret) From patchwork Tue May 11 07:18:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandru Ardelean X-Patchwork-Id: 12249963 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=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham 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 C7AA5C43462 for ; Tue, 11 May 2021 07:18:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A4EC961920 for ; Tue, 11 May 2021 07:18:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230387AbhEKHTq (ORCPT ); Tue, 11 May 2021 03:19:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35800 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230458AbhEKHTq (ORCPT ); Tue, 11 May 2021 03:19:46 -0400 Received: from mail-ej1-x634.google.com (mail-ej1-x634.google.com [IPv6:2a00:1450:4864:20::634]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E785EC061760 for ; Tue, 11 May 2021 00:18:39 -0700 (PDT) Received: by mail-ej1-x634.google.com with SMTP id gx5so28196952ejb.11 for ; Tue, 11 May 2021 00:18:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=deviqon.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=nkXARO+FVrewyUKtJO4CN2s0umqdJR4fAYNaOAsTCV0=; b=sw7IA3puMIZUCEHNi/9LZInTcptD0kkIuSCOJNgIf1DHv0/VOBUca/sjpXjo/3rR3u YuCI8JAkzMPgGtTejq3tEfvbPbTp+oxrvOfWmhH+weCE/vX51SL74NCf4972gplf4aOU VTwIN6FQHFxix43Z17ovCx8rdeiP9jSCnGXh2MkLnMJe2FxssXOwBmhUOyQ3L9ANuKQl Gvu2Iz7kKunrNZroipn1VYNjxtyEeGvJHUDiIsvPU1yva3dCY4Ai3oHuGe9qJmnWLTvb yReCqJAW2u6GUN4U4IZNDJOgB3Ka8BccjxvuQXqrKN3pdtugPazj3BPEDt8BASGoG6S9 gltQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=nkXARO+FVrewyUKtJO4CN2s0umqdJR4fAYNaOAsTCV0=; b=Z8hn2tJv74wXKkrJK61fp+v7UsR8unE7CAryT0DV87k0F2czArNEitJ4mPp1YEAU/x AOBfLeYFsridYQPaNEqqqK5ZQv+hKDgzMccnjdg+6mscSQQPEzxEgbzSu2FQbz4gE7b9 5BPUbD4p+Ktya/SPyb2QDqj6kc1qNNGBBG7WoyRwN9BArRARr6aKP5qoz2mjikNW2aBi 3PqniI4Z8bCuUVTqzPthG3TPAshDLs5bOZ5MnS/d5kQqlv17iSIAxA3s8pSw58JJT8Ra lpbCnm7BNAUaLZfhvFtWGOcO84fHwU0/YfQR/K22ABS85Y4tiuXEwjHRKGj/wocu60wy ZJ3A== X-Gm-Message-State: AOAM533hRiE/qaUkZW177iVnEa08DQNqZRBKzae1YgpXzct4KcAnxGmC YeA0g9aP6NOt1lRuEP4OGma2HoiC+Oy7Jm3P X-Google-Smtp-Source: ABdhPJzepc5AHcq7Rr6OJegiCXqwNOmhwBiIycp3MzqQZ6A3yUR4YpZ1jvKxntP5YyR/I5VH/UDd8g== X-Received: by 2002:a17:906:e118:: with SMTP id gj24mr30587048ejb.205.1620717518423; Tue, 11 May 2021 00:18:38 -0700 (PDT) Received: from neptune.. ([188.27.131.122]) by smtp.gmail.com with ESMTPSA id i6sm13871558eds.83.2021.05.11.00.18.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 May 2021 00:18:38 -0700 (PDT) From: Alexandru Ardelean To: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Cc: jic23@kernel.org, Jonathan.Cameron@huawei.com, alexandru.tachici@analog.com, linux@deviqon.com, Alexandru Ardelean , Alexandru Ardelean Subject: [PATCH v2 03/12] iio: adc: ad7192: Avoid disabling a clock that was never enabled. Date: Tue, 11 May 2021 10:18:22 +0300 Message-Id: <20210511071831.576145-4-aardelean@deviqon.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210511071831.576145-1-aardelean@deviqon.com> References: <20210511071831.576145-1-aardelean@deviqon.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org From: Jonathan Cameron Found by inspection. If the internal clock source is being used, the driver doesn't call clk_prepare_enable() and as such we should not call clk_disable_unprepare() Use the same condition to protect the disable path as is used on the enable one. Note this will all get simplified when the driver moves over to a full devm_ flow, but that would make backporting the fix harder. Fix obviously predates move out of staging, but backporting will become more complex (and is unlikely to happen), hence that patch is given in the fixes tag. Fixes: b581f748cce0 ("staging: iio: adc: ad7192: move out of staging") Cc: Alexandru Tachici Reviewed-by: Alexandru Ardelean Signed-off-by: Jonathan Cameron Signed-off-by: Alexandru Ardelean --- drivers/iio/adc/ad7192.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/iio/adc/ad7192.c b/drivers/iio/adc/ad7192.c index 2ed580521d81..d3be67aa0522 100644 --- a/drivers/iio/adc/ad7192.c +++ b/drivers/iio/adc/ad7192.c @@ -1014,7 +1014,9 @@ static int ad7192_probe(struct spi_device *spi) return 0; error_disable_clk: - clk_disable_unprepare(st->mclk); + if (st->clock_sel == AD7192_CLK_EXT_MCLK1_2 || + st->clock_sel == AD7192_CLK_EXT_MCLK2) + clk_disable_unprepare(st->mclk); error_remove_trigger: ad_sd_cleanup_buffer_and_trigger(indio_dev); error_disable_dvdd: @@ -1031,7 +1033,9 @@ static int ad7192_remove(struct spi_device *spi) struct ad7192_state *st = iio_priv(indio_dev); iio_device_unregister(indio_dev); - clk_disable_unprepare(st->mclk); + if (st->clock_sel == AD7192_CLK_EXT_MCLK1_2 || + st->clock_sel == AD7192_CLK_EXT_MCLK2) + clk_disable_unprepare(st->mclk); ad_sd_cleanup_buffer_and_trigger(indio_dev); regulator_disable(st->dvdd); From patchwork Tue May 11 07:18:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandru Ardelean X-Patchwork-Id: 12249965 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=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham 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 B45A4C433B4 for ; Tue, 11 May 2021 07:18:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 90E8561920 for ; Tue, 11 May 2021 07:18:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230525AbhEKHTx (ORCPT ); Tue, 11 May 2021 03:19:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35814 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230464AbhEKHTr (ORCPT ); Tue, 11 May 2021 03:19:47 -0400 Received: from mail-ej1-x62a.google.com (mail-ej1-x62a.google.com [IPv6:2a00:1450:4864:20::62a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E9C70C06175F for ; Tue, 11 May 2021 00:18:40 -0700 (PDT) Received: by mail-ej1-x62a.google.com with SMTP id m12so28262416eja.2 for ; Tue, 11 May 2021 00:18:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=deviqon.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=XNwmkBzZYIFL26toATaXnA6vBIR2hsJAqgIvqXkXahc=; b=rL1t/OA5iFqAAVFaUgqU8/qOC1fXTXetUit2+dCzeQIA5XA1NVIekfZtrEYG/hoyJd mDea5W2GAF8iR2yctLrIoozosqwvfeV4pqjdFRlEF6anphOoMy3znY6g1Y2Vb/h3SpTH S2eXKdHY6SppmdmnNhJJ8tMSj3iDpG2jmgeKNkRLk9D36jOLecnhBqTuCzEgrypiQt8s fhzw/DIltX4L00ECrQaCXqan9+ZUrlzk32S3a8Aj/Z5YgAB7njCOOsLZ0Y9E0aKeE7/p KXgbLoD6Y9qVafKE3eIGfz9N44NTZxjwFeFncpbY03VXZsskh/ZMXxk9huy4bd3XBYRz TKRg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=XNwmkBzZYIFL26toATaXnA6vBIR2hsJAqgIvqXkXahc=; b=NVnNe9j7ptyKEimCAvH5M+KedUj+lOacsnZIcsnTBWvht+XcXXB+6uxZHSZQXiLC3h w4MgRh5fUFBXw5aG2vu9Vhrxf3w8SF7TI0ylYQ7bkEhNYa1SlWFdiGBbeyvfE8+1pVA9 RApMwk2RzIp9dEwkNf7HRIe4BkHln5Yed6SDDkOea6ec9WTaCQNnpjTGkf1nMEf0iCXS g3Oj8lUQgXOAaX9WinYIBLwk32yd7eN6z2i4xcTSfTirYNKDIuSvkZknpHteNEm+wtR9 1fSSp1RIzNE6rPSLHlWElsS0l6QGfDb+Mm1NhPFJEtmuvlukoyfiIRN+2/f5UOUHvk2Q 818A== X-Gm-Message-State: AOAM531BjRn5R5Ojg8Gfpp6QUDNyxWchBYqADjqsyPkFYkfceDqybnFq WUoh9V50ys7KpMzbFlzhV8Gr4gpqCrGCt7rZ X-Google-Smtp-Source: ABdhPJxHbrZV8hZ/8iaLTB7WZ3Q7l6Ac+0VRGx//5bIi9r1LNA4GC0lH6yqE065mFKC7gi3wuNnG3Q== X-Received: by 2002:a17:907:2117:: with SMTP id qn23mr30099405ejb.48.1620717519437; Tue, 11 May 2021 00:18:39 -0700 (PDT) Received: from neptune.. ([188.27.131.122]) by smtp.gmail.com with ESMTPSA id i6sm13871558eds.83.2021.05.11.00.18.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 May 2021 00:18:39 -0700 (PDT) From: Alexandru Ardelean To: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Cc: jic23@kernel.org, Jonathan.Cameron@huawei.com, alexandru.tachici@analog.com, linux@deviqon.com, Alexandru Ardelean Subject: [PATCH v2 04/12] iio: adc: ad7192: handle zero Avdd regulator value as error Date: Tue, 11 May 2021 10:18:23 +0300 Message-Id: <20210511071831.576145-5-aardelean@deviqon.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210511071831.576145-1-aardelean@deviqon.com> References: <20210511071831.576145-1-aardelean@deviqon.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org This change fixes a corner-case, where the returned voltage is actually zero. This is also what patch ab0afa65bbc7 ("staging: iio: adc: ad7192: fail probe on get_voltage") was trying to do. But as Jonathan pointed out, a zero-value would signal that the probe has succeeded, putting the driver is a semi-initialized state. Fixes: ab0afa65bbc7 ("staging: iio: adc: ad7192: fail probe on get_voltage") Cc: Alexandru Tachici Signed-off-by: Alexandru Ardelean --- drivers/iio/adc/ad7192.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/iio/adc/ad7192.c b/drivers/iio/adc/ad7192.c index d3be67aa0522..79df54e0dc96 100644 --- a/drivers/iio/adc/ad7192.c +++ b/drivers/iio/adc/ad7192.c @@ -950,6 +950,11 @@ static int ad7192_probe(struct spi_device *spi) } voltage_uv = regulator_get_voltage(st->avdd); + if (voltage_uv == 0) { + ret = -EINVAL; + dev_err(&spi->dev, "Zero value provided for AVdd supply\n"); + goto error_disable_avdd; + } if (voltage_uv > 0) { st->int_vref_mv = voltage_uv / 1000; From patchwork Tue May 11 07:18:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandru Ardelean X-Patchwork-Id: 12249967 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=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham 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 0A2E1C433B4 for ; Tue, 11 May 2021 07:18:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E3A126187E for ; Tue, 11 May 2021 07:18:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231159AbhEKHT4 (ORCPT ); Tue, 11 May 2021 03:19:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35822 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230487AbhEKHTs (ORCPT ); Tue, 11 May 2021 03:19:48 -0400 Received: from mail-ej1-x62b.google.com (mail-ej1-x62b.google.com [IPv6:2a00:1450:4864:20::62b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DD4E1C061763 for ; Tue, 11 May 2021 00:18:41 -0700 (PDT) Received: by mail-ej1-x62b.google.com with SMTP id l4so28219866ejc.10 for ; Tue, 11 May 2021 00:18:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=deviqon.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=T22i+g53k1fhCLKh9tB02Omn3iL2iUzJbrWzhjCB28A=; b=IbeNYO/ZVaMjfhUYkNzfSaEsrZPxLeTnlbkNUcX0lACa54dq7fJLx5DhRZuDYRAG/l wyUHMxs0dgKAc2CguJdtGXVlRJOIa75mRm0ZDnaK75b04CqUFxdrSnswN792MLcxGXQF tMYH8pS7bsvMWRfXsemb3P9BTWSlzlKJGIftGn9ummdaPt9j/4KBF+R4NQHEujw6vslj k01OKfCvYbNlq5JQIs0P4lT/TbEOBbyDIZrt2rlGt61dVn9vNBZ13JQeRlqGBjjWNf7D rhJbQTmiO3zKvo/2WSCBPQqtfa/zcV9+HtEVB2hclkCNExW+CjPxhlQrDylaLKHY0lEs qZAA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=T22i+g53k1fhCLKh9tB02Omn3iL2iUzJbrWzhjCB28A=; b=TlWr7IudfroaKIcPG0yCN6nGVRWObzaiSkYonGwS58I+YRiV1LNr9MmuE5BF0EhpKY XoXuqoeAW3jDqifQIAj39WhglJyUi5GrZdOuXp1EMPaw9yavt3GGFHWdma2Lq7TuW5I/ oiVSV7OfZ1jnDydDIFIxAjKxaQlAvlXcYUz3fAMWsIfNVgF5Y+S/HlBhgXPEh6IJwFqz xoXLBHQus3uT+AOJyez1g7QFY9qnRswjQpCUe3/wYTmESkiH+e5ld1JwXQ+8jBaKFNtv lX8o7rIHYB6XmX9AuSrvGkHOShzweSaNkjUQ4bp+NbHCax3LvzEdeK0Q4IHEcjQKlQCw Gw1Q== X-Gm-Message-State: AOAM5300qCGx9TCVITsmVQpk8/vfJhhP6/AlfMfrnnjQg6n8coXWJ2Br UI/uYs/gTNupckiQ7CNsKCcd44Z6n3cps1sr X-Google-Smtp-Source: ABdhPJxO0MjKwg9BHybjx4Vbbd5UhUIy5BNrBduH+WLl+4BiyP4UT+GjfWBVbW9j8O2Uc5aZPAeI7A== X-Received: by 2002:a17:906:c01a:: with SMTP id e26mr30240339ejz.300.1620717520426; Tue, 11 May 2021 00:18:40 -0700 (PDT) Received: from neptune.. ([188.27.131.122]) by smtp.gmail.com with ESMTPSA id i6sm13871558eds.83.2021.05.11.00.18.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 May 2021 00:18:40 -0700 (PDT) From: Alexandru Ardelean To: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Cc: jic23@kernel.org, Jonathan.Cameron@huawei.com, alexandru.tachici@analog.com, linux@deviqon.com, Alexandru Ardelean Subject: [PATCH v2 05/12] iio: adc: ad_sigma_delta: introduct devm_ad_sd_setup_buffer_and_trigger() Date: Tue, 11 May 2021 10:18:24 +0300 Message-Id: <20210511071831.576145-6-aardelean@deviqon.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210511071831.576145-1-aardelean@deviqon.com> References: <20210511071831.576145-1-aardelean@deviqon.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org This is a version of ad_sd_setup_buffer_and_trigger() with all underlying functions (that are used) being replaced with their device-managed variants. One thing to take care here is with {devm_}iio_trigger_alloc(), where both functions take a parent-device object as the first parameter. To make sure nothing quirky is happening, the devm_ad_sd_probe_trigger() function is checking that the provided 'dev' reference is the same as the one stored on the 'struct ad_sigma_delta' driver data. Signed-off-by: Alexandru Ardelean --- drivers/iio/adc/ad_sigma_delta.c | 60 ++++++++++++++++++++++++++ include/linux/iio/adc/ad_sigma_delta.h | 3 ++ 2 files changed, 63 insertions(+) diff --git a/drivers/iio/adc/ad_sigma_delta.c b/drivers/iio/adc/ad_sigma_delta.c index 69b979331ccd..d5801a47be07 100644 --- a/drivers/iio/adc/ad_sigma_delta.c +++ b/drivers/iio/adc/ad_sigma_delta.c @@ -513,6 +513,46 @@ static int ad_sd_probe_trigger(struct iio_dev *indio_dev) return ret; } +static int devm_ad_sd_probe_trigger(struct device *dev, struct iio_dev *indio_dev) +{ + struct ad_sigma_delta *sigma_delta = iio_device_get_drvdata(indio_dev); + int ret; + + if (dev != &sigma_delta->spi->dev) { + dev_err(dev, "Trigger parent should be '%s', got '%s'\n", + dev_name(dev), dev_name(&sigma_delta->spi->dev)); + return -EFAULT; + } + + sigma_delta->trig = devm_iio_trigger_alloc(dev, "%s-dev%d", indio_dev->name, + iio_device_id(indio_dev)); + if (sigma_delta->trig == NULL) + return -ENOMEM; + + sigma_delta->trig->ops = &ad_sd_trigger_ops; + init_completion(&sigma_delta->completion); + + sigma_delta->irq_dis = true; + ret = devm_request_irq(dev, sigma_delta->spi->irq, + ad_sd_data_rdy_trig_poll, + sigma_delta->info->irq_flags | IRQF_NO_AUTOEN, + indio_dev->name, + sigma_delta); + if (ret) + return ret; + + iio_trigger_set_drvdata(sigma_delta->trig, sigma_delta); + + ret = devm_iio_trigger_register(dev, sigma_delta->trig); + if (ret) + return ret; + + /* select default trigger */ + indio_dev->trig = iio_trigger_get(sigma_delta->trig); + + return 0; +} + static void ad_sd_remove_trigger(struct iio_dev *indio_dev) { struct ad_sigma_delta *sigma_delta = iio_device_get_drvdata(indio_dev); @@ -556,6 +596,26 @@ void ad_sd_cleanup_buffer_and_trigger(struct iio_dev *indio_dev) } EXPORT_SYMBOL_GPL(ad_sd_cleanup_buffer_and_trigger); +/** + * devm_ad_sd_setup_buffer_and_trigger() - Device-managed buffer & trigger setup + * @dev: Device object to which to bind the life-time of the resources attached + * @indio_dev: The IIO device + */ +int devm_ad_sd_setup_buffer_and_trigger(struct device *dev, struct iio_dev *indio_dev) +{ + int ret; + + ret = devm_iio_triggered_buffer_setup(dev, indio_dev, + &iio_pollfunc_store_time, + &ad_sd_trigger_handler, + &ad_sd_buffer_setup_ops); + if (ret) + return ret; + + return devm_ad_sd_probe_trigger(dev, indio_dev); +} +EXPORT_SYMBOL_GPL(devm_ad_sd_setup_buffer_and_trigger); + /** * ad_sd_init() - Initializes a ad_sigma_delta struct * @sigma_delta: The ad_sigma_delta device diff --git a/include/linux/iio/adc/ad_sigma_delta.h b/include/linux/iio/adc/ad_sigma_delta.h index 7199280d89ca..be81ad39fb7a 100644 --- a/include/linux/iio/adc/ad_sigma_delta.h +++ b/include/linux/iio/adc/ad_sigma_delta.h @@ -26,6 +26,7 @@ struct ad_sd_calib_data { }; struct ad_sigma_delta; +struct device; struct iio_dev; /** @@ -135,6 +136,8 @@ int ad_sd_init(struct ad_sigma_delta *sigma_delta, struct iio_dev *indio_dev, int ad_sd_setup_buffer_and_trigger(struct iio_dev *indio_dev); void ad_sd_cleanup_buffer_and_trigger(struct iio_dev *indio_dev); +int devm_ad_sd_setup_buffer_and_trigger(struct device *dev, struct iio_dev *indio_dev); + int ad_sd_validate_trigger(struct iio_dev *indio_dev, struct iio_trigger *trig); #endif From patchwork Tue May 11 07:18:25 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandru Ardelean X-Patchwork-Id: 12249969 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=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham 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 2F30EC433ED for ; Tue, 11 May 2021 07:18:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 148AF61482 for ; Tue, 11 May 2021 07:18:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231167AbhEKHUA (ORCPT ); Tue, 11 May 2021 03:20:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35848 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230519AbhEKHTx (ORCPT ); Tue, 11 May 2021 03:19:53 -0400 Received: from mail-ed1-x531.google.com (mail-ed1-x531.google.com [IPv6:2a00:1450:4864:20::531]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B5D05C06138A for ; Tue, 11 May 2021 00:18:42 -0700 (PDT) Received: by mail-ed1-x531.google.com with SMTP id g14so21646851edy.6 for ; Tue, 11 May 2021 00:18:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=deviqon.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=/XPGApaju6LMGXyrepb+ba3cN9cbtBiZnKqABRzBNdQ=; b=Ngt4ldMeIjtsK1bTG61nOj3xVLJzWiXbfQ46F9gLilKHvEUmgNh1wjCjb5VfbmNdnf +P0f43WWGEe9IJMDH7sVDTAsHwTYX2wa1LGNII+4RfWJV6+09NjMrkDSUy2l1Z/r0uzW 7cEKm0IGNTSXWOU7VmQr0GCikcEY6PkCzPQIlHeW6Yo9mZqheDfpz5MuGySR2bucm7YK LsBJcoBtnx1XqWC9ysiVXIppSdQ/0HCnBxe/Xk4/g7EKuZ8dE2RUTcc+JhLRLL4Z/Gxq FBB6tYsoqoytdBCg+Y1zirEaeCaaojTKws5OWKTkBw6vAuPx0Vd1mAzr35XmcvkVeVPY r1NQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=/XPGApaju6LMGXyrepb+ba3cN9cbtBiZnKqABRzBNdQ=; b=FxjdTjVlAwBn5Im+mL8hnhAjhbdVONZeK3dosAylOODxYT7SrDam1EvHftIAskcWEY XDLd1x2NZtc5e6KseCwkWbZJM/TEqt+CpZCWbMg0sADbV5UYBHOlHQNqHweZAXWEpRUn YtWgCko/GimQ9znm5GHlaiLb4rBC9wPXDK9zmN3rWP26b0s0IbC18C095wBvq7YbISb1 m4EMEvd+2V0mci/5EAYjf/TvpE/y0YarkCF+UCXClKC5xelLtW2yxp105mXnlIMAzHbt KBagG9nse2ysnNP00bEC3A4mDaR9y105/78LrX9NdFVn5yaCkbKK9P0z3N6tsiXrQ0hg e5UA== X-Gm-Message-State: AOAM5322xOAhKO/nGDKcyif5362eth9j2NvOUZbI4S5yWHLCSB9wbsvA b0tv3szowRXosJArQ0DwEqoWvjLi9ra/sZrs X-Google-Smtp-Source: ABdhPJxaKUHgxAySwLu+3JslTTK3k1lv2ct/WvvBRWyge9DS+apk5ucW9haqyU+lwe6yNsx5ZMc8rw== X-Received: by 2002:a05:6402:40c:: with SMTP id q12mr1848526edv.0.1620717521297; Tue, 11 May 2021 00:18:41 -0700 (PDT) Received: from neptune.. ([188.27.131.122]) by smtp.gmail.com with ESMTPSA id i6sm13871558eds.83.2021.05.11.00.18.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 May 2021 00:18:41 -0700 (PDT) From: Alexandru Ardelean To: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Cc: jic23@kernel.org, Jonathan.Cameron@huawei.com, alexandru.tachici@analog.com, linux@deviqon.com, Alexandru Ardelean Subject: [PATCH v2 06/12] iio: adc: ad7793: convert to device-managed functions Date: Tue, 11 May 2021 10:18:25 +0300 Message-Id: <20210511071831.576145-7-aardelean@deviqon.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210511071831.576145-1-aardelean@deviqon.com> References: <20210511071831.576145-1-aardelean@deviqon.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org With the devm_ad_sd_setup_buffer_and_trigger() helper, it's a bit easier now to convert the probe of the AD7793 driver to use device-managed functions. Only the regulator disable requires a devm_add_action_or_reset() callback. This change does that, cleaning up the driver a bit. Signed-off-by: Alexandru Ardelean --- drivers/iio/adc/ad7793.c | 53 ++++++++++++---------------------------- 1 file changed, 15 insertions(+), 38 deletions(-) diff --git a/drivers/iio/adc/ad7793.c b/drivers/iio/adc/ad7793.c index 5e980a06258e..5dab2e5b5bac 100644 --- a/drivers/iio/adc/ad7793.c +++ b/drivers/iio/adc/ad7793.c @@ -768,6 +768,11 @@ static const struct ad7793_chip_info ad7793_chip_info_tbl[] = { }, }; +static void ad7793_reg_disable(void *reg) +{ + regulator_disable(reg); +} + static int ad7793_probe(struct spi_device *spi) { const struct ad7793_platform_data *pdata = spi->dev.platform_data; @@ -802,11 +807,13 @@ static int ad7793_probe(struct spi_device *spi) if (ret) return ret; + ret = devm_add_action_or_reset(&spi->dev, ad7793_reg_disable, st->reg); + if (ret) + return ret; + vref_mv = regulator_get_voltage(st->reg); - if (vref_mv < 0) { - ret = vref_mv; - goto error_disable_reg; - } + if (vref_mv < 0) + return vref_mv; vref_mv /= 1000; } else { @@ -816,50 +823,21 @@ static int ad7793_probe(struct spi_device *spi) st->chip_info = &ad7793_chip_info_tbl[spi_get_device_id(spi)->driver_data]; - spi_set_drvdata(spi, indio_dev); - indio_dev->name = spi_get_device_id(spi)->name; indio_dev->modes = INDIO_DIRECT_MODE; indio_dev->channels = st->chip_info->channels; indio_dev->num_channels = st->chip_info->num_channels; indio_dev->info = st->chip_info->iio_info; - ret = ad_sd_setup_buffer_and_trigger(indio_dev); + ret = devm_ad_sd_setup_buffer_and_trigger(&spi->dev, indio_dev); if (ret) - goto error_disable_reg; + return ret; ret = ad7793_setup(indio_dev, pdata, vref_mv); if (ret) - goto error_remove_trigger; - - ret = iio_device_register(indio_dev); - if (ret) - goto error_remove_trigger; - - return 0; - -error_remove_trigger: - ad_sd_cleanup_buffer_and_trigger(indio_dev); -error_disable_reg: - if (pdata->refsel != AD7793_REFSEL_INTERNAL) - regulator_disable(st->reg); - - return ret; -} - -static int ad7793_remove(struct spi_device *spi) -{ - const struct ad7793_platform_data *pdata = spi->dev.platform_data; - struct iio_dev *indio_dev = spi_get_drvdata(spi); - struct ad7793_state *st = iio_priv(indio_dev); - - iio_device_unregister(indio_dev); - ad_sd_cleanup_buffer_and_trigger(indio_dev); - - if (pdata->refsel != AD7793_REFSEL_INTERNAL) - regulator_disable(st->reg); + return ret; - return 0; + return devm_iio_device_register(&spi->dev, indio_dev); } static const struct spi_device_id ad7793_id[] = { @@ -881,7 +859,6 @@ static struct spi_driver ad7793_driver = { .name = "ad7793", }, .probe = ad7793_probe, - .remove = ad7793_remove, .id_table = ad7793_id, }; module_spi_driver(ad7793_driver); From patchwork Tue May 11 07:18:26 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandru Ardelean X-Patchwork-Id: 12249971 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=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham 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 6AC78C433ED for ; Tue, 11 May 2021 07:18:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5079E61482 for ; Tue, 11 May 2021 07:18:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231185AbhEKHUD (ORCPT ); Tue, 11 May 2021 03:20:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35866 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231143AbhEKHTz (ORCPT ); Tue, 11 May 2021 03:19:55 -0400 Received: from mail-ed1-x530.google.com (mail-ed1-x530.google.com [IPv6:2a00:1450:4864:20::530]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AEB84C061343 for ; Tue, 11 May 2021 00:18:43 -0700 (PDT) Received: by mail-ed1-x530.google.com with SMTP id r11so6775299edt.13 for ; Tue, 11 May 2021 00:18:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=deviqon.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=uQxvMGRCpOgSDyhSi99qzEO+Zt/+Ct8uEX5NstuSgr8=; b=BM5I0JVYaWiKMQYRSDBOk8/kvBqUYIC0tO+Bt8CRC+OpkAGt+A89wDgurdK07jqEcs tRuWxcOzb6SCItKXbxx4ybqxBgjYTGzyM6Z7eTG2nyvC2jAV/shP3OO9ob5Fd7YjROpI pOnO/puKxV00u5dBltQwCVibua/yLGQG1cN10BiLeRXe5JnkqMq9n3o7YXpk+8z9Djf/ X4rk0LkePWOV4uZOpc2jNG42x8vff7kYvDU8Ko6QKnPcKRnMoEX1X/Q3y7N1xVj8Kv4j P4ypWEw9NJWQmQRxVTnKz4xAr91ciDqclj2Mx29BPQK1PnaIc2usDcqKYqtcy0K6RKMk QSxQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=uQxvMGRCpOgSDyhSi99qzEO+Zt/+Ct8uEX5NstuSgr8=; b=nHlscpKGHDR40+m9OnMuvJXjT1iQ6OBwD6p5sCaf5Ou7zqO/4/lDFuwV9TFn5KlQj9 gZIRHhGWOGsVVrDrkcwpzWl3Ncgd11LMXqMwPC+1UqfpgQCqRxj9Q0hA09wWaNeBUMCW R8xrQRUP4YrUDrTHMGeQtD8y7gsw5CMc66utQ8ZFNwvQZBmYPPgRS7ArH0xC3aVn3dz4 HT+XMp2o/fx19mh0PapFyO5drxMba/4perC7Vg98aFg0TqXUCVU8IFqwVxvE26ReHmqk hn/ZZUEd7oXixS0wVNvUq6vFgmOjvLIBwGfuB/PHi8e4pOogwgJY+0EdRD0MN4y4Oihx dyxg== X-Gm-Message-State: AOAM532ynORP0NJoCjeO9UlPehu51hO42wZn75uqBm0rNSC3nctKAOJW cbwQJLERZ2K/yN/FaX5JFn2LJV2hkGL/Lh5m X-Google-Smtp-Source: ABdhPJyWmZENVLyR/8uAQK3cr5JCztj0xscC2XVLz41SUr+tpPkmyz3NxAq61n/rZb1VSNGRtJ1rmQ== X-Received: by 2002:aa7:d14e:: with SMTP id r14mr33660734edo.119.1620717522217; Tue, 11 May 2021 00:18:42 -0700 (PDT) Received: from neptune.. ([188.27.131.122]) by smtp.gmail.com with ESMTPSA id i6sm13871558eds.83.2021.05.11.00.18.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 May 2021 00:18:41 -0700 (PDT) From: Alexandru Ardelean To: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Cc: jic23@kernel.org, Jonathan.Cameron@huawei.com, alexandru.tachici@analog.com, linux@deviqon.com, Alexandru Ardelean Subject: [PATCH v2 07/12] iio: adc: ad7791: convert to device-managed functions Date: Tue, 11 May 2021 10:18:26 +0300 Message-Id: <20210511071831.576145-8-aardelean@deviqon.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210511071831.576145-1-aardelean@deviqon.com> References: <20210511071831.576145-1-aardelean@deviqon.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org With the devm_ad_sd_setup_buffer_and_trigger() helper, it's a bit easier now to convert the probe of the AD7791 driver to use device-managed functions. Only the regulator disable requires a devm_add_action_or_reset() callback. This change does that, cleaning up the driver a bit. Signed-off-by: Alexandru Ardelean --- drivers/iio/adc/ad7791.c | 44 ++++++++++++---------------------------- 1 file changed, 13 insertions(+), 31 deletions(-) diff --git a/drivers/iio/adc/ad7791.c b/drivers/iio/adc/ad7791.c index d57ad966e17c..cb579aa89f39 100644 --- a/drivers/iio/adc/ad7791.c +++ b/drivers/iio/adc/ad7791.c @@ -394,6 +394,11 @@ static int ad7791_setup(struct ad7791_state *st, st->mode); } +static void ad7791_reg_disable(void *reg) +{ + regulator_disable(reg); +} + static int ad7791_probe(struct spi_device *spi) { struct ad7791_platform_data *pdata = spi->dev.platform_data; @@ -420,11 +425,13 @@ static int ad7791_probe(struct spi_device *spi) if (ret) return ret; + ret = devm_add_action_or_reset(&spi->dev, ad7791_reg_disable, st->reg); + if (ret) + return ret; + st->info = &ad7791_chip_infos[spi_get_device_id(spi)->driver_data]; ad_sd_init(&st->sd, indio_dev, spi, &ad7791_sigma_delta_info); - spi_set_drvdata(spi, indio_dev); - indio_dev->name = spi_get_device_id(spi)->name; indio_dev->modes = INDIO_DIRECT_MODE; indio_dev->channels = st->info->channels; @@ -434,39 +441,15 @@ static int ad7791_probe(struct spi_device *spi) else indio_dev->info = &ad7791_no_filter_info; - ret = ad_sd_setup_buffer_and_trigger(indio_dev); + ret = devm_ad_sd_setup_buffer_and_trigger(&spi->dev, indio_dev); if (ret) - goto error_disable_reg; + return ret; ret = ad7791_setup(st, pdata); if (ret) - goto error_remove_trigger; - - ret = iio_device_register(indio_dev); - if (ret) - goto error_remove_trigger; - - return 0; - -error_remove_trigger: - ad_sd_cleanup_buffer_and_trigger(indio_dev); -error_disable_reg: - regulator_disable(st->reg); - - return ret; -} - -static int ad7791_remove(struct spi_device *spi) -{ - struct iio_dev *indio_dev = spi_get_drvdata(spi); - struct ad7791_state *st = iio_priv(indio_dev); - - iio_device_unregister(indio_dev); - ad_sd_cleanup_buffer_and_trigger(indio_dev); - - regulator_disable(st->reg); + return ret; - return 0; + return devm_iio_device_register(&spi->dev, indio_dev); } static const struct spi_device_id ad7791_spi_ids[] = { @@ -484,7 +467,6 @@ static struct spi_driver ad7791_driver = { .name = "ad7791", }, .probe = ad7791_probe, - .remove = ad7791_remove, .id_table = ad7791_spi_ids, }; module_spi_driver(ad7791_driver); From patchwork Tue May 11 07:18:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandru Ardelean X-Patchwork-Id: 12249973 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=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham 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 B1F82C433B4 for ; Tue, 11 May 2021 07:19:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 92BF161490 for ; Tue, 11 May 2021 07:19:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231200AbhEKHUF (ORCPT ); Tue, 11 May 2021 03:20:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35870 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231151AbhEKHT4 (ORCPT ); Tue, 11 May 2021 03:19:56 -0400 Received: from mail-ed1-x52e.google.com (mail-ed1-x52e.google.com [IPv6:2a00:1450:4864:20::52e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8DA36C061345 for ; Tue, 11 May 2021 00:18:44 -0700 (PDT) Received: by mail-ed1-x52e.google.com with SMTP id b17so21651695ede.0 for ; Tue, 11 May 2021 00:18:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=deviqon.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=uc0zdIjPCIp6p3E6v5GazM0pebh4DygGLW4ST5XuVM0=; b=Aru7+pGXL6R0fKf9Jmg/OM2Euu4Z/QeHfRHArxk3rw3BwaumbAzRhOyoJe/N5Qu53W mN0FLGnp4HHB7MsxdV0AlYQBRfXkpBZqM+v/48mq3w+veteFNtYcUUKch7BZayL8bu/7 Ji2hxG7MOGP4im1WkWf8U9Syq5wkJIRlK79ylF2bPhqnySZZZ8U7F+Kce2F2RfHjbImp ZGdme/cWDsPP1b4JHMcsaXoBZF+nMV2aUl7aDAIw+4Pi9FCk9ldD7exJAvm0l7NgKhKL UN6v4bl5LR6GmNOCfTYI3vFwut0LVPKyW/ACqsrb7D9aUxPSOqDhpeVQ9tisKz616oRU 4HmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=uc0zdIjPCIp6p3E6v5GazM0pebh4DygGLW4ST5XuVM0=; b=Qz7lX6FyatH7Fpio+P5zOPblAGHOhEXoPXJi9jCxzcmOASIO+7mk3TsLztrMvGm7DW b4OEu29/LlkGZMWQwcWaO4whi8CNaV/PNex8KEqfnjJn5AIzWecKWIQtDZzBilu3ESil +LP73INbOcslm+bjOuzEJ5jzPpdCcsjrmwmur9A73uGkRFwAAGnS1gSKSeZpcNvnjCub +bSv+DrPd7WTENSqxL0c1OtvWQc8c8IpCVeKGOJv8Xh/15ZmP+e5yoV77+JGBRbxGUN5 emqoCck2JEjZWPj1OMSRo//BtkaSrcIa8gbb6g5Qx+uuxakhzZm7LoL9ACvwulz0p2H+ muWA== X-Gm-Message-State: AOAM531VVY6Y5CwL2H9vnMctU5IlRyUrQNw/ZWlW3mwrKt5Xpds4vEGD Q1xb3Gjz9iQY/oZLg52L/qBnkal1KptJaHma X-Google-Smtp-Source: ABdhPJxMfpNCThxaSXxZu/zeq9MhUQEZSVfqasIONNR0kSUdu0iZVVxhvo+41a/bkv+W/g4FsDm4Kw== X-Received: by 2002:a05:6402:3587:: with SMTP id y7mr34772094edc.197.1620717523129; Tue, 11 May 2021 00:18:43 -0700 (PDT) Received: from neptune.. ([188.27.131.122]) by smtp.gmail.com with ESMTPSA id i6sm13871558eds.83.2021.05.11.00.18.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 May 2021 00:18:42 -0700 (PDT) From: Alexandru Ardelean To: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Cc: jic23@kernel.org, Jonathan.Cameron@huawei.com, alexandru.tachici@analog.com, linux@deviqon.com, Alexandru Ardelean Subject: [PATCH v2 08/12] iio: adc: ad7780: convert to device-managed functions Date: Tue, 11 May 2021 10:18:27 +0300 Message-Id: <20210511071831.576145-9-aardelean@deviqon.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210511071831.576145-1-aardelean@deviqon.com> References: <20210511071831.576145-1-aardelean@deviqon.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org With the devm_ad_sd_setup_buffer_and_trigger() helper, it's a bit easier now to convert the probe of the AD7780 driver to use device-managed functions. Only the regulator disable requires a devm_add_action_or_reset() callback. This change does that, cleaning up the driver a bit. Signed-off-by: Alexandru Ardelean --- drivers/iio/adc/ad7780.c | 38 ++++++++++---------------------------- 1 file changed, 10 insertions(+), 28 deletions(-) diff --git a/drivers/iio/adc/ad7780.c b/drivers/iio/adc/ad7780.c index 42e7e8e595d1..42bb952f4738 100644 --- a/drivers/iio/adc/ad7780.c +++ b/drivers/iio/adc/ad7780.c @@ -300,6 +300,11 @@ static int ad7780_init_gpios(struct device *dev, struct ad7780_state *st) return 0; } +static void ad7780_reg_disable(void *reg) +{ + regulator_disable(reg); +} + static int ad7780_probe(struct spi_device *spi) { struct ad7780_state *st; @@ -318,8 +323,6 @@ static int ad7780_probe(struct spi_device *spi) st->chip_info = &ad7780_chip_info_tbl[spi_get_device_id(spi)->driver_data]; - spi_set_drvdata(spi, indio_dev); - indio_dev->name = spi_get_device_id(spi)->name; indio_dev->modes = INDIO_DIRECT_MODE; indio_dev->channels = &st->chip_info->channel; @@ -340,35 +343,15 @@ static int ad7780_probe(struct spi_device *spi) return ret; } - ret = ad_sd_setup_buffer_and_trigger(indio_dev); + ret = devm_add_action_or_reset(&spi->dev, ad7780_reg_disable, st->reg); if (ret) - goto error_disable_reg; + return ret; - ret = iio_device_register(indio_dev); + ret = devm_ad_sd_setup_buffer_and_trigger(&spi->dev, indio_dev); if (ret) - goto error_cleanup_buffer_and_trigger; - - return 0; - -error_cleanup_buffer_and_trigger: - ad_sd_cleanup_buffer_and_trigger(indio_dev); -error_disable_reg: - regulator_disable(st->reg); - - return ret; -} - -static int ad7780_remove(struct spi_device *spi) -{ - struct iio_dev *indio_dev = spi_get_drvdata(spi); - struct ad7780_state *st = iio_priv(indio_dev); - - iio_device_unregister(indio_dev); - ad_sd_cleanup_buffer_and_trigger(indio_dev); - - regulator_disable(st->reg); + return ret; - return 0; + return devm_iio_device_register(&spi->dev, indio_dev); } static const struct spi_device_id ad7780_id[] = { @@ -385,7 +368,6 @@ static struct spi_driver ad7780_driver = { .name = "ad7780", }, .probe = ad7780_probe, - .remove = ad7780_remove, .id_table = ad7780_id, }; module_spi_driver(ad7780_driver); From patchwork Tue May 11 07:18:28 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandru Ardelean X-Patchwork-Id: 12249975 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=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham 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 E3A83C43460 for ; Tue, 11 May 2021 07:19:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B367D61920 for ; Tue, 11 May 2021 07:19:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230498AbhEKHUL (ORCPT ); Tue, 11 May 2021 03:20:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35848 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230501AbhEKHT7 (ORCPT ); Tue, 11 May 2021 03:19:59 -0400 Received: from mail-ed1-x530.google.com (mail-ed1-x530.google.com [IPv6:2a00:1450:4864:20::530]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7CE38C061348 for ; Tue, 11 May 2021 00:18:45 -0700 (PDT) Received: by mail-ed1-x530.google.com with SMTP id b17so21651734ede.0 for ; Tue, 11 May 2021 00:18:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=deviqon.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=YxA8FQYDWbxe8BPqwCO+yOABH8hUl4nAhrh9q+4gOxs=; b=he2GENrRhDW+bZxoqb8MKMBMQc8bYzFKlxGSCc/RtgNDE4FeeeT7KwUKqf1IyN7XTI ZzE6fAXeKtqfvE5taWRvNTrbjh6C2sc+TVO9vkyYqblMDCYxO2U6un7qysqWqKizoEZj qSYatZDFhrRgH0xMA9eMVvskwg5W81+O2EW8lDLt5p/u1Zx+yS6OMrnSduy0f6ZKGN8h l3U3w8igjLBYJkmk49/fvz0/9bUfKXFcF/3rO0bJzGS+BoxVLrLOMZTkPOZoeyw6RjbW Z9pKmQyPebN8mQCh0YadDa3a4k4OnZOgycI1vFto98AGgY0/NiOZXL67vH+qPy8jDzcE gGcQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=YxA8FQYDWbxe8BPqwCO+yOABH8hUl4nAhrh9q+4gOxs=; b=GmmgnpbqgH8GqEH5Qds66Q+ga+8S4J63F9ld0rU2bbXXJH8HCXJPfo6IF4+s6EECCu AlN7heTMdTE1QpB8Uz1XzPppUUcezPB3h5bITdwaTOIJkl0C+4pQ95URGLx4GcWfo0dZ lAvgez89P7YD2mKeUMaRLFg273pZlX6PQgi2mlkqNrFHThmwWbFF9xCFQN7Mj9ghjs67 WnEplRz8jZ5aC+iqBhCgPf9a7p8wrRumy9oSrFBBpbaJKLV3p8nQqhsrEw9mNPb7LmJ2 kvRpf4Vb+dEfidTHUoO2AvvUQeXzMBXYKnCJ9puz5YIihUr0cwl8wSwhPxxkwS0zMQpn BFZA== X-Gm-Message-State: AOAM531hFOSm15kL+BvmVlNzrfZnRCS8jVd6JX4E9v0NVok0K83iswOo ENUhm1ciR62bC27icA6zOM98pSnQEKcXydwu X-Google-Smtp-Source: ABdhPJypim42rK6++a+BuJWBRwFnCXwcg+zQwnKYHu6Q0j+hTNeTv1EKkr+T8oDqfH+xznhKnO9BMQ== X-Received: by 2002:aa7:d3c2:: with SMTP id o2mr34437469edr.111.1620717524035; Tue, 11 May 2021 00:18:44 -0700 (PDT) Received: from neptune.. ([188.27.131.122]) by smtp.gmail.com with ESMTPSA id i6sm13871558eds.83.2021.05.11.00.18.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 May 2021 00:18:43 -0700 (PDT) From: Alexandru Ardelean To: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Cc: jic23@kernel.org, Jonathan.Cameron@huawei.com, alexandru.tachici@analog.com, linux@deviqon.com, Alexandru Ardelean Subject: [PATCH v2 09/12] iio: adc: ad7192: use devm_clk_get_optional() for mclk Date: Tue, 11 May 2021 10:18:28 +0300 Message-Id: <20210511071831.576145-10-aardelean@deviqon.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210511071831.576145-1-aardelean@deviqon.com> References: <20210511071831.576145-1-aardelean@deviqon.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org The devm_clk_get_optional() helper returns NULL when devm_clk_get() returns -ENOENT. This makes things slightly cleaner. The added benefit is mostly cosmetic. Also, a minor detail with this call, is that the reference for the parent device is taken as `spi->dev` instead of `&st->sd.spi->dev` (which looks a little quirky). Signed-off-by: Alexandru Ardelean --- drivers/iio/adc/ad7192.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/iio/adc/ad7192.c b/drivers/iio/adc/ad7192.c index 79df54e0dc96..18e731f1471a 100644 --- a/drivers/iio/adc/ad7192.c +++ b/drivers/iio/adc/ad7192.c @@ -326,7 +326,7 @@ static int ad7192_of_clock_select(struct ad7192_state *st) clock_sel = AD7192_CLK_INT; /* use internal clock */ - if (PTR_ERR(st->mclk) == -ENOENT) { + if (st->mclk) { if (of_property_read_bool(np, "adi,int-clock-output-enable")) clock_sel = AD7192_CLK_INT_CO; } else { @@ -986,8 +986,8 @@ static int ad7192_probe(struct spi_device *spi) st->fclk = AD7192_INT_FREQ_MHZ; - st->mclk = devm_clk_get(&st->sd.spi->dev, "mclk"); - if (IS_ERR(st->mclk) && PTR_ERR(st->mclk) != -ENOENT) { + st->mclk = devm_clk_get_optional(&spi->dev, "mclk"); + if (IS_ERR(st->mclk)) { ret = PTR_ERR(st->mclk); goto error_remove_trigger; } From patchwork Tue May 11 07:18:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandru Ardelean X-Patchwork-Id: 12249977 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=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham 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 5C0D4C43461 for ; Tue, 11 May 2021 07:19:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3443F61920 for ; Tue, 11 May 2021 07:19:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231153AbhEKHUL (ORCPT ); Tue, 11 May 2021 03:20:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35850 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230497AbhEKHT7 (ORCPT ); Tue, 11 May 2021 03:19:59 -0400 Received: from mail-ed1-x536.google.com (mail-ed1-x536.google.com [IPv6:2a00:1450:4864:20::536]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9AF9CC06134A for ; Tue, 11 May 2021 00:18:46 -0700 (PDT) Received: by mail-ed1-x536.google.com with SMTP id c22so21614543edn.7 for ; Tue, 11 May 2021 00:18:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=deviqon.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=OjyXmokyyEi4mYmoSxzJwRJFFFsatuf8PBQju296W0w=; b=RqZyvI4Ref0gaXFImbjvyEYHYYueIwC+5l3WQ5s6Ma8gtNeBRdTde2JfhfTyTgg0KO HdzF8qEscFr2XzjK+a+yFiKr/qngecyHYqzjTD2BGHUDa7G8hcvqKVaf31kgV5RFeCfy gnHL9SsLaAVGeIn1cDHqvHoAAfam1iNTiAijp+E6/ZNDw2QxFUuOvjfGG2JIw4nIP8Yc CzOoDcq/Ir68YnFrWd8671fqtoAWSmPGVTe20ZJsGg/UhOvgZnkxlr8rmNMq9M6+/5ML YGTiGKUoNxOfORG/LtSKlauRmL/zyATuTvUu9G0LsU8bBIhXh0e2H3HZN1r6wnqVSLuP G2iQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=OjyXmokyyEi4mYmoSxzJwRJFFFsatuf8PBQju296W0w=; b=cHw3I9NF2pA5NubYBZquGdnzZLkTEZSsySwhYTRaqYNVG0ahuFjQWhTM4UxQodwbwO GilmSg2EQ4Hu7fDSbC5PbA65ZRKN8vChaomkWjNPQXu17zrOEKr4csGi5XCGG3mE97F0 iHyUx67UQgRnSY62lH3+mN/xy2ukxFsjpgCRH3lnPWzFqcdKrWMTWl92J6qQ1a/puBfW v1cdERb36QMOXx0HFJRKh4Pp0TO4Sw6JG5m9dkj1xbL+43IlUVLtVc2ZDyT+b0eMUBML OpdfEtp2Jrw/xScGV3FdoijGN8jEzQ2iFuZLRXGAyrhXPOqfQXPMQFqPa+Ywgn54KSb5 EoWg== X-Gm-Message-State: AOAM531tLjU/oVJYVLPIqKibygP5iH9Avsdu713e96Z9mrAyECI7l771 ykir8d5D09qbjnP2yOMzTWyV1z1RS60dHna3 X-Google-Smtp-Source: ABdhPJwen16A/yUfPkZAwST2ej+Wa8csmfGwlYKlau0yXL5+0GnwnMzdPYr7oXsnLKKSKhi1X5kadg== X-Received: by 2002:aa7:d146:: with SMTP id r6mr34822500edo.344.1620717525130; Tue, 11 May 2021 00:18:45 -0700 (PDT) Received: from neptune.. ([188.27.131.122]) by smtp.gmail.com with ESMTPSA id i6sm13871558eds.83.2021.05.11.00.18.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 May 2021 00:18:44 -0700 (PDT) From: Alexandru Ardelean To: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Cc: jic23@kernel.org, Jonathan.Cameron@huawei.com, alexandru.tachici@analog.com, linux@deviqon.com, Alexandru Ardelean Subject: [PATCH v2 10/12] iio: adc: ad7192: convert to device-managed functions Date: Tue, 11 May 2021 10:18:29 +0300 Message-Id: <20210511071831.576145-11-aardelean@deviqon.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210511071831.576145-1-aardelean@deviqon.com> References: <20210511071831.576145-1-aardelean@deviqon.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org With the devm_ad_sd_setup_buffer_and_trigger() helper, it's a bit easier now to convert the probe of the AD7192 driver to use device-managed functions. The regulators and the mclk requires devm_add_action_or_reset() callbacks though. Signed-off-by: Alexandru Ardelean --- drivers/iio/adc/ad7192.c | 93 ++++++++++++++++------------------------ 1 file changed, 37 insertions(+), 56 deletions(-) diff --git a/drivers/iio/adc/ad7192.c b/drivers/iio/adc/ad7192.c index 18e731f1471a..50696959c018 100644 --- a/drivers/iio/adc/ad7192.c +++ b/drivers/iio/adc/ad7192.c @@ -908,6 +908,16 @@ static int ad7192_channels_config(struct iio_dev *indio_dev) return 0; } +static void ad7192_reg_disable(void *reg) +{ + regulator_disable(reg); +} + +static void ad7192_clk_disable(void *clk) +{ + clk_disable_unprepare(clk); +} + static int ad7192_probe(struct spi_device *spi) { struct ad7192_state *st; @@ -937,41 +947,44 @@ static int ad7192_probe(struct spi_device *spi) return ret; } + ret = devm_add_action_or_reset(&spi->dev, ad7192_reg_disable, st->avdd); + if (ret) + return ret; + st->dvdd = devm_regulator_get(&spi->dev, "dvdd"); - if (IS_ERR(st->dvdd)) { - ret = PTR_ERR(st->dvdd); - goto error_disable_avdd; - } + if (IS_ERR(st->dvdd)) + return PTR_ERR(st->dvdd); ret = regulator_enable(st->dvdd); if (ret) { dev_err(&spi->dev, "Failed to enable specified DVdd supply\n"); - goto error_disable_avdd; + return ret; } + ret = devm_add_action_or_reset(&spi->dev, ad7192_reg_disable, st->dvdd); + if (ret) + return ret; + voltage_uv = regulator_get_voltage(st->avdd); if (voltage_uv == 0) { - ret = -EINVAL; dev_err(&spi->dev, "Zero value provided for AVdd supply\n"); - goto error_disable_avdd; + return -EINVAL; } if (voltage_uv > 0) { st->int_vref_mv = voltage_uv / 1000; } else { - ret = voltage_uv; dev_err(&spi->dev, "Device tree error, reference voltage undefined\n"); - goto error_disable_avdd; + return voltage_uv; } - spi_set_drvdata(spi, indio_dev); st->chip_info = of_device_get_match_data(&spi->dev); indio_dev->name = st->chip_info->name; indio_dev->modes = INDIO_DIRECT_MODE; ret = ad7192_channels_config(indio_dev); if (ret < 0) - goto error_disable_dvdd; + return ret; if (st->chip_info->chip_id == CHIPID_AD7195) indio_dev->info = &ad7195_info; @@ -980,17 +993,15 @@ static int ad7192_probe(struct spi_device *spi) ad_sd_init(&st->sd, indio_dev, spi, &ad7192_sigma_delta_info); - ret = ad_sd_setup_buffer_and_trigger(indio_dev); + ret = devm_ad_sd_setup_buffer_and_trigger(&spi->dev, indio_dev); if (ret) - goto error_disable_dvdd; + return ret; st->fclk = AD7192_INT_FREQ_MHZ; st->mclk = devm_clk_get_optional(&spi->dev, "mclk"); - if (IS_ERR(st->mclk)) { - ret = PTR_ERR(st->mclk); - goto error_remove_trigger; - } + if (IS_ERR(st->mclk)) + return PTR_ERR(st->mclk); st->clock_sel = ad7192_of_clock_select(st); @@ -998,55 +1009,26 @@ static int ad7192_probe(struct spi_device *spi) st->clock_sel == AD7192_CLK_EXT_MCLK2) { ret = clk_prepare_enable(st->mclk); if (ret < 0) - goto error_remove_trigger; + return ret; + + ret = devm_add_action_or_reset(&spi->dev, ad7192_clk_disable, + st->mclk); + if (ret) + return ret; st->fclk = clk_get_rate(st->mclk); if (!ad7192_valid_external_frequency(st->fclk)) { - ret = -EINVAL; dev_err(&spi->dev, "External clock frequency out of bounds\n"); - goto error_disable_clk; + return -EINVAL; } } ret = ad7192_setup(st, spi->dev.of_node); if (ret) - goto error_disable_clk; - - ret = iio_device_register(indio_dev); - if (ret < 0) - goto error_disable_clk; - return 0; - -error_disable_clk: - if (st->clock_sel == AD7192_CLK_EXT_MCLK1_2 || - st->clock_sel == AD7192_CLK_EXT_MCLK2) - clk_disable_unprepare(st->mclk); -error_remove_trigger: - ad_sd_cleanup_buffer_and_trigger(indio_dev); -error_disable_dvdd: - regulator_disable(st->dvdd); -error_disable_avdd: - regulator_disable(st->avdd); - - return ret; -} - -static int ad7192_remove(struct spi_device *spi) -{ - struct iio_dev *indio_dev = spi_get_drvdata(spi); - struct ad7192_state *st = iio_priv(indio_dev); - - iio_device_unregister(indio_dev); - if (st->clock_sel == AD7192_CLK_EXT_MCLK1_2 || - st->clock_sel == AD7192_CLK_EXT_MCLK2) - clk_disable_unprepare(st->mclk); - ad_sd_cleanup_buffer_and_trigger(indio_dev); - - regulator_disable(st->dvdd); - regulator_disable(st->avdd); + return ret; - return 0; + return devm_iio_device_register(&spi->dev, indio_dev); } static const struct of_device_id ad7192_of_match[] = { @@ -1064,7 +1046,6 @@ static struct spi_driver ad7192_driver = { .of_match_table = ad7192_of_match, }, .probe = ad7192_probe, - .remove = ad7192_remove, }; module_spi_driver(ad7192_driver); From patchwork Tue May 11 07:18:30 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandru Ardelean X-Patchwork-Id: 12249979 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=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham 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 BAF07C433ED for ; Tue, 11 May 2021 07:19:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A0F5161920 for ; Tue, 11 May 2021 07:19:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231160AbhEKHUM (ORCPT ); Tue, 11 May 2021 03:20:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35852 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231173AbhEKHUA (ORCPT ); Tue, 11 May 2021 03:20:00 -0400 Received: from mail-ed1-x52e.google.com (mail-ed1-x52e.google.com [IPv6:2a00:1450:4864:20::52e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 91A50C06175F for ; Tue, 11 May 2021 00:18:47 -0700 (PDT) Received: by mail-ed1-x52e.google.com with SMTP id g14so21647092edy.6 for ; Tue, 11 May 2021 00:18:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=deviqon.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=b3CIlvHXWAL8LnevCxF+tYL0znrNNdyr/u/1pI8y5A4=; b=Q9Yiffs7kIWaAJUdImwXQl9bJZ1qt4xfgG0/itKjN+yhbkCyz9xeY8zuKsx1CIL/26 Ay3g0lYtsmKIOXiyfqUGI8Y73XqWMxjZ6Z6tDlQed1WkioOQinFLnu1tZqgKi5KhAtZ9 KPWKls3sJbJ7Nzxn1qc4oMgnYq3U0V0ZgkYHLtVqCT/qvukxM63g8TMlF4nHqKXmmiT8 m8MVULZVk3uleKYK2ZfTyEX8073xzNKEh2CVG5cItGExTW7LVLuNfNm1bZK43cYn+YBL XsAVfvwxPEDHm7U8li8rW7bA4AlrSB3RbO+bHjDUk46npg/ZStDCFhYvBu6MBg5JBYC2 k7gg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=b3CIlvHXWAL8LnevCxF+tYL0znrNNdyr/u/1pI8y5A4=; b=QDomDMMAX2G6Jgk2vDfGZvxDgBXe/Iort9yFfzjWHPUbfhW5ReCqdhHI/8tAX/m9A6 mDjHKzEkqAJuLn487uWklTgQQ695UGJbONbDX++4lr0knrSzSrAdoapm7vec3Mb/HhF5 waPFscqGR1fl0hPJ0kKNqKQNksXYXPK4DfaWdAM0oszx2eFrdueyehneTVEfZhmeodXU MDUj1KHIKH3H1LDwHaYk4U6npnyWSh/aIiUDIdWtK3TKoevyaFeN+vapLxroetdki2QW BzT3BAMuHrVHVyH2zx/FpqsCnsG7ssmY2KE/T7bNxT84N9j3QPJwgP5VyJPwaogNjxsD JoUg== X-Gm-Message-State: AOAM5325UJqA9mBsEbhfrMtIaYj7kItFNy8s6ttlIHuX41flfytD6jme 76MfB8+Uf2fnoWwWdUVyUC01mDcugT+6U2Lx X-Google-Smtp-Source: ABdhPJzrVgKabMEuxuqxzVqkTcIeHZTJS/kbU5P6vyScgM3T66gl5Quj3ZOKSgGv6P31BqbA4JVqLA== X-Received: by 2002:aa7:cb92:: with SMTP id r18mr3834454edt.246.1620717526111; Tue, 11 May 2021 00:18:46 -0700 (PDT) Received: from neptune.. ([188.27.131.122]) by smtp.gmail.com with ESMTPSA id i6sm13871558eds.83.2021.05.11.00.18.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 May 2021 00:18:45 -0700 (PDT) From: Alexandru Ardelean To: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Cc: jic23@kernel.org, Jonathan.Cameron@huawei.com, alexandru.tachici@analog.com, linux@deviqon.com, Alexandru Ardelean , Alexandru Ardelean Subject: [PATCH v2 11/12] iio: adc: ad7124: Use devm_ managed calls for all of probe() + drop remove() Date: Tue, 11 May 2021 10:18:30 +0300 Message-Id: <20210511071831.576145-12-aardelean@deviqon.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210511071831.576145-1-aardelean@deviqon.com> References: <20210511071831.576145-1-aardelean@deviqon.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org From: Jonathan Cameron As not many steps were not already devm_ managed, use devm_add_action_or_reset() to handle the rest. This also uses the new devm_ad_sd_setup_buffer_and_trigger() function. Reviewed-by: Alexandru Ardelean Signed-off-by: Jonathan Cameron Signed-off-by: Alexandru Ardelean --- drivers/iio/adc/ad7124.c | 48 +++++++++++++--------------------------- 1 file changed, 15 insertions(+), 33 deletions(-) diff --git a/drivers/iio/adc/ad7124.c b/drivers/iio/adc/ad7124.c index a27db78ea13e..e45c600fccc0 100644 --- a/drivers/iio/adc/ad7124.c +++ b/drivers/iio/adc/ad7124.c @@ -862,6 +862,11 @@ static void ad7124_reg_disable(void *r) regulator_disable(r); } +static void ad7124_clk_disable(void *c) +{ + clk_disable_unprepare(c); +} + static int ad7124_probe(struct spi_device *spi) { const struct ad7124_chip_info *info; @@ -883,8 +888,6 @@ static int ad7124_probe(struct spi_device *spi) ad_sd_init(&st->sd, indio_dev, spi, &ad7124_sigma_delta_info); - spi_set_drvdata(spi, indio_dev); - indio_dev->name = st->chip_info->name; indio_dev->modes = INDIO_DIRECT_MODE; indio_dev->info = &ad7124_info; @@ -922,48 +925,28 @@ static int ad7124_probe(struct spi_device *spi) if (ret < 0) return ret; + ret = devm_add_action_or_reset(&spi->dev, ad7124_clk_disable, st->mclk); + if (ret) + return ret; + ret = ad7124_soft_reset(st); if (ret < 0) - goto error_clk_disable_unprepare; + return ret; ret = ad7124_check_chip_id(st); if (ret) - goto error_clk_disable_unprepare; + return ret; ret = ad7124_setup(st); if (ret < 0) - goto error_clk_disable_unprepare; + return ret; - ret = ad_sd_setup_buffer_and_trigger(indio_dev); + ret = devm_ad_sd_setup_buffer_and_trigger(&spi->dev, indio_dev); if (ret < 0) - goto error_clk_disable_unprepare; - - ret = iio_device_register(indio_dev); - if (ret < 0) { - dev_err(&spi->dev, "Failed to register iio device\n"); - goto error_remove_trigger; - } - - return 0; - -error_remove_trigger: - ad_sd_cleanup_buffer_and_trigger(indio_dev); -error_clk_disable_unprepare: - clk_disable_unprepare(st->mclk); - - return ret; -} - -static int ad7124_remove(struct spi_device *spi) -{ - struct iio_dev *indio_dev = spi_get_drvdata(spi); - struct ad7124_state *st = iio_priv(indio_dev); + return ret; - iio_device_unregister(indio_dev); - ad_sd_cleanup_buffer_and_trigger(indio_dev); - clk_disable_unprepare(st->mclk); + return devm_iio_device_register(&spi->dev, indio_dev); - return 0; } static const struct of_device_id ad7124_of_match[] = { @@ -981,7 +964,6 @@ static struct spi_driver ad71124_driver = { .of_match_table = ad7124_of_match, }, .probe = ad7124_probe, - .remove = ad7124_remove, }; module_spi_driver(ad71124_driver); From patchwork Tue May 11 07:18:31 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandru Ardelean X-Patchwork-Id: 12249981 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=-16.0 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, UNWANTED_LANGUAGE_BODY,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham 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 53BA7C433B4 for ; Tue, 11 May 2021 07:19:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 38F5461482 for ; Tue, 11 May 2021 07:19:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231173AbhEKHUN (ORCPT ); Tue, 11 May 2021 03:20:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35862 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230521AbhEKHUA (ORCPT ); Tue, 11 May 2021 03:20:00 -0400 Received: from mail-ej1-x632.google.com (mail-ej1-x632.google.com [IPv6:2a00:1450:4864:20::632]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 936D0C06134C for ; Tue, 11 May 2021 00:18:48 -0700 (PDT) Received: by mail-ej1-x632.google.com with SMTP id b25so28196178eju.5 for ; Tue, 11 May 2021 00:18:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=deviqon.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=jHJAupFk4VVa7z8ctgtedCHBJAEpOSwdi50lGjIjnM8=; b=bTvYTEb2K77cls873u2IXLpinsxfp5BKbdvPHfvZpBd/42WCGy9rj1yWQP4m9ICcHi oHZS1jrg1Kj9A3sMjavCtXrGDl3tMQFBLrMULkUBRSuYAugbephewj2Y35hObGWGI/IG Ey5tjMbqQezTgnEcDZzvpBPillnJfDX+SEPmakcLrwN+zgX/Ney0xycu/aTq/OIKxHiW p2hx0dH3AZzB59ACnTvSpxl0Lcgq1DGxsIyvm3dDo18SasDGxRMgSnNDekXd3HfTc96O CHwZ1s1SqvyhVb1zGm583BYcr7VYwFbSJ04iNsqskfzvq/57NdfLjXStEWfpv9FLVJIR 8vpg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=jHJAupFk4VVa7z8ctgtedCHBJAEpOSwdi50lGjIjnM8=; b=JGfTQn5vMxUSrQ1ZDsQz2Osi8Eic4ghJ27y0a50CG8c9OgMg0XN7cxyqiIioF/auDe A+HmBter/GtlqnSbymYbx/HpXX4wa2OdvEkSkLwQ/jlN+FYUUdYQtP1SzEsLRSBQlPoB Z25FbAHrwGyWUOrGXebNKiIe2OiHKtERA6Kdj5yEMjT/4lXzapWCmeUP1eyMBROzc6NG 4zE+nCznvw0oODIqdSvYe3hU0VChKUeEEcLbRqqii5ujFIOb2zS0BwyPe9tzQtHe0M6k WXGASPADklOXsTErLUZqAoRavFBqjExLlrgLEd9r0foBxZDP9ZnF9vO3tA/nmm04lhn2 X21g== X-Gm-Message-State: AOAM530cmLdk36Nty/89hcaOzg7uxeM7SeteNcSYXwLOKVSd4JBTSVMk QJFRwzzuzHve5xA0Gr6BgJRV0YAeFTyeMBV6 X-Google-Smtp-Source: ABdhPJxygVxUK46NgvIsEGDJHQrrsQdBrEMNOhzgin1vAaLwUSQjU522mKyN7SLxXS6kwpYQ4/YMWg== X-Received: by 2002:a17:906:91d3:: with SMTP id b19mr30172072ejx.242.1620717527122; Tue, 11 May 2021 00:18:47 -0700 (PDT) Received: from neptune.. ([188.27.131.122]) by smtp.gmail.com with ESMTPSA id i6sm13871558eds.83.2021.05.11.00.18.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 May 2021 00:18:46 -0700 (PDT) From: Alexandru Ardelean To: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Cc: jic23@kernel.org, Jonathan.Cameron@huawei.com, alexandru.tachici@analog.com, linux@deviqon.com, Alexandru Ardelean Subject: [PATCH v2 12/12] iio: adc: ad_sigma_delta: remove ad_sd_{setup,cleanup}_buffer_and_trigger() Date: Tue, 11 May 2021 10:18:31 +0300 Message-Id: <20210511071831.576145-13-aardelean@deviqon.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210511071831.576145-1-aardelean@deviqon.com> References: <20210511071831.576145-1-aardelean@deviqon.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org Since all AD Sigma-Delta drivers now use the devm_ad_sd_setup_buffer_and_trigger() function, we can remove the old ad_sd_{setup,cleanup}_buffer_and_trigger() functions. This way we can discourage new drivers that use the ad_sigma_delta lib-driver to use these (older functions). Signed-off-by: Alexandru Ardelean --- drivers/iio/adc/ad_sigma_delta.c | 86 -------------------------- include/linux/iio/adc/ad_sigma_delta.h | 3 - 2 files changed, 89 deletions(-) diff --git a/drivers/iio/adc/ad_sigma_delta.c b/drivers/iio/adc/ad_sigma_delta.c index d5801a47be07..1d652d9b2f5c 100644 --- a/drivers/iio/adc/ad_sigma_delta.c +++ b/drivers/iio/adc/ad_sigma_delta.c @@ -470,49 +470,6 @@ EXPORT_SYMBOL_GPL(ad_sd_validate_trigger); static const struct iio_trigger_ops ad_sd_trigger_ops = { }; -static int ad_sd_probe_trigger(struct iio_dev *indio_dev) -{ - struct ad_sigma_delta *sigma_delta = iio_device_get_drvdata(indio_dev); - int ret; - - sigma_delta->trig = iio_trigger_alloc(&sigma_delta->spi->dev, - "%s-dev%d", indio_dev->name, - iio_device_id(indio_dev)); - if (sigma_delta->trig == NULL) { - ret = -ENOMEM; - goto error_ret; - } - sigma_delta->trig->ops = &ad_sd_trigger_ops; - init_completion(&sigma_delta->completion); - - sigma_delta->irq_dis = true; - ret = request_irq(sigma_delta->spi->irq, - ad_sd_data_rdy_trig_poll, - sigma_delta->info->irq_flags | IRQF_NO_AUTOEN, - indio_dev->name, - sigma_delta); - if (ret) - goto error_free_trig; - - iio_trigger_set_drvdata(sigma_delta->trig, sigma_delta); - - ret = iio_trigger_register(sigma_delta->trig); - if (ret) - goto error_free_irq; - - /* select default trigger */ - indio_dev->trig = iio_trigger_get(sigma_delta->trig); - - return 0; - -error_free_irq: - free_irq(sigma_delta->spi->irq, sigma_delta); -error_free_trig: - iio_trigger_free(sigma_delta->trig); -error_ret: - return ret; -} - static int devm_ad_sd_probe_trigger(struct device *dev, struct iio_dev *indio_dev) { struct ad_sigma_delta *sigma_delta = iio_device_get_drvdata(indio_dev); @@ -553,49 +510,6 @@ static int devm_ad_sd_probe_trigger(struct device *dev, struct iio_dev *indio_de return 0; } -static void ad_sd_remove_trigger(struct iio_dev *indio_dev) -{ - struct ad_sigma_delta *sigma_delta = iio_device_get_drvdata(indio_dev); - - iio_trigger_unregister(sigma_delta->trig); - free_irq(sigma_delta->spi->irq, sigma_delta); - iio_trigger_free(sigma_delta->trig); -} - -/** - * ad_sd_setup_buffer_and_trigger() - - * @indio_dev: The IIO device - */ -int ad_sd_setup_buffer_and_trigger(struct iio_dev *indio_dev) -{ - int ret; - - ret = iio_triggered_buffer_setup(indio_dev, &iio_pollfunc_store_time, - &ad_sd_trigger_handler, &ad_sd_buffer_setup_ops); - if (ret) - return ret; - - ret = ad_sd_probe_trigger(indio_dev); - if (ret) { - iio_triggered_buffer_cleanup(indio_dev); - return ret; - } - - return 0; -} -EXPORT_SYMBOL_GPL(ad_sd_setup_buffer_and_trigger); - -/** - * ad_sd_cleanup_buffer_and_trigger() - - * @indio_dev: The IIO device - */ -void ad_sd_cleanup_buffer_and_trigger(struct iio_dev *indio_dev) -{ - ad_sd_remove_trigger(indio_dev); - iio_triggered_buffer_cleanup(indio_dev); -} -EXPORT_SYMBOL_GPL(ad_sd_cleanup_buffer_and_trigger); - /** * devm_ad_sd_setup_buffer_and_trigger() - Device-managed buffer & trigger setup * @dev: Device object to which to bind the life-time of the resources attached diff --git a/include/linux/iio/adc/ad_sigma_delta.h b/include/linux/iio/adc/ad_sigma_delta.h index be81ad39fb7a..c525fd51652f 100644 --- a/include/linux/iio/adc/ad_sigma_delta.h +++ b/include/linux/iio/adc/ad_sigma_delta.h @@ -133,9 +133,6 @@ int ad_sd_calibrate_all(struct ad_sigma_delta *sigma_delta, int ad_sd_init(struct ad_sigma_delta *sigma_delta, struct iio_dev *indio_dev, struct spi_device *spi, const struct ad_sigma_delta_info *info); -int ad_sd_setup_buffer_and_trigger(struct iio_dev *indio_dev); -void ad_sd_cleanup_buffer_and_trigger(struct iio_dev *indio_dev); - int devm_ad_sd_setup_buffer_and_trigger(struct device *dev, struct iio_dev *indio_dev); int ad_sd_validate_trigger(struct iio_dev *indio_dev, struct iio_trigger *trig);