From patchwork Wed May 12 17:49:03 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandru Ardelean X-Patchwork-Id: 12254447 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,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 7711EC43470 for ; Wed, 12 May 2021 18:21:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5D408613D3 for ; Wed, 12 May 2021 18:21:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242688AbhELSWA (ORCPT ); Wed, 12 May 2021 14:22:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50448 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350514AbhELRvH (ORCPT ); Wed, 12 May 2021 13:51:07 -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 0AB81C06138A for ; Wed, 12 May 2021 10:49:58 -0700 (PDT) Received: by mail-ej1-x62f.google.com with SMTP id k10so5028940ejj.8 for ; Wed, 12 May 2021 10:49:57 -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=qg7B+p/EdpaiT5gvz8IazDMbbMPiWk9AJUJJLOX5vNYzliT7X3pyFCTYphE+eWpyFT pnzyX3hL1IquBRjvIKYFWfDQErVLkvyNwtHGDP+R7WDY1LMzeJEj+2ngyLkN9Ei1QkR6 P8Wp/EABTMd4H97FmKQ7DGN6Y4GTrP6cmbyWCjJkE1qs1x6APee0qKsGJDPWBwXjZ4Uh wA5iPLULgRq1vosVtyEaXwnWyL6kxoC+ANXj3lF3BUAMCfjeViP3tJrVfEQ6d2PPn+qK WYPsLEICOvDN+XcdTDWeRTV7GG1opmSMRv5NcVu+bTeKvUdlKCs5fBCxxvzsDi+n5gEZ GwZQ== 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=T/+s80zSNmvScPUiXrzws+UPvnoLBZKrAGMneYXqQ5v2qhWbrJDUsI1WDt/1p4eMXN U4GervRLEdZY/QkFQcOH7PH5eUcSNLI0nXj1iQMvAaR3v5VPqu3emkJdhczrhbO7zTFd /92llostO5TVTNJ4BdKUbzAz774Wp2uxnYUobsI+uxqpik1NWwrFxYvpFkoEYtqKg5VF kSRcgJaPlhIhOllxsjWRUGcbH7kNtwg34WEjRQyxkCcWwciXK+D87Bx451bo9tlDR96a FF5DyTRrSCh8N3PaLC6dKBzwdH19zipwGXvKgF0qk6/U9iadDvoqHxHRBmq34v77qDjj JRHA== X-Gm-Message-State: AOAM5314PwxzBcmAJ5RqKXXmROPzGKL6vz/nxoLmssOLH3XG5ZNbvwZX lvh5VJlFlVVJVUWRv56smrsmMAHetCjP6g== X-Google-Smtp-Source: ABdhPJwRM2YdDAwUgqdu+As6vFNfWcxNjZJd+2LpncXGnTaKBSs/Qj0AxhzAn8V71kWgDJbc4EfQng== X-Received: by 2002:a17:906:7c45:: with SMTP id g5mr37981556ejp.368.1620841796574; Wed, 12 May 2021 10:49:56 -0700 (PDT) Received: from neptune.. ([5.2.193.191]) by smtp.gmail.com with ESMTPSA id r16sm338058edq.87.2021.05.12.10.49.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 May 2021 10:49:56 -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 v3 01/12] iio: adc: ad7124: Fix missbalanced regulator enable / disable on error. Date: Wed, 12 May 2021 20:49:03 +0300 Message-Id: <20210512174914.10549-2-aardelean@deviqon.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210512174914.10549-1-aardelean@deviqon.com> References: <20210512174914.10549-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 Wed May 12 17:49:04 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandru Ardelean X-Patchwork-Id: 12254449 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,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 D6954C4360C for ; Wed, 12 May 2021 18:21:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A3E15613EE for ; Wed, 12 May 2021 18:21:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242704AbhELSWB (ORCPT ); Wed, 12 May 2021 14:22:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50464 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350519AbhELRvK (ORCPT ); Wed, 12 May 2021 13:51:10 -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 2F1E0C06138B for ; Wed, 12 May 2021 10:49:59 -0700 (PDT) Received: by mail-ej1-x62f.google.com with SMTP id s20so30731413ejr.9 for ; Wed, 12 May 2021 10:49:59 -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=ARiwzjzixi6kh5+4cwI0MVWB0GweYEnmFJ2+cGNn+FZTzgODruNy6osicsuDPE3nE4 4rjOlH2wXakFQgZyYyO7Yn1lgsTLMIKgLQYVsPfi4N2z2pydUd83fC78WrcA0NZPJRx5 HW6NAS2hVe4/dlf0qSQsoscJZ3UQ5x2lxG7S+Y0N6Q/whgA7CALQn52psQ3AfPM8QSbE /zS6RNtTWyDdlhVzd5Aa/8nYX7/Ksr+VfUZcBDXkS3B+mGfqbhJIlpsie7wfGxSzAANA xhxVI4O19Oa/Scyk3vDeTMBFy2dL+cbUG174pRmWdYPnD7WSon1Cz0QeHCRcQx/e+hSl fZTw== 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=An3eLH21an083I9qo2654rbbkM365iDFINQGAkj68hGDTjm2o+9SZjXL7GfW3JmZpC +khz4b5nrk0eF5tZ5VOy7ww1rrBWIpu6PqWBXkz+cQhezD97KT0J5DwR2IxCSMF2yy/1 bICrFxwLtosrhemRBbpjWX5gdMd3T+orJQ19KoeG1jEM6RJ4PYbWkt1aazzR2m1e1ugk vPziQc/SXmPLtPwsOtRCRhtzqoZf7qxRrpCizws/1kVGNoDZe4ZOF3AaVbT7CMoU1fBb cj0MbD3/1ikRwR6+IREZBXIx+ZGPB+g+gGo/eBqSL59x48x22xKkfj7ETBpT2RxV6SXk vO6g== X-Gm-Message-State: AOAM533jxcXHaP81kZcYzXoWfwzxGjtJ6l2CjXxDFtgRmY3BfC2kyRDS SKzazThDpQvoqqLLzzHhJ/aiU8lJKlb0SQ== X-Google-Smtp-Source: ABdhPJzo7tmImWNPOb4Lq7Z3+yra7hePoowXdeUssxDVr3PJD3+Y/BkCZA1BuGocp2anTSOX9BNOfg== X-Received: by 2002:a17:907:3da4:: with SMTP id he36mr38201476ejc.308.1620841797674; Wed, 12 May 2021 10:49:57 -0700 (PDT) Received: from neptune.. ([5.2.193.191]) by smtp.gmail.com with ESMTPSA id r16sm338058edq.87.2021.05.12.10.49.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 May 2021 10:49:57 -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 v3 02/12] iio: adc: ad7124: Fix potential overflow due to non sequential channel numbers Date: Wed, 12 May 2021 20:49:04 +0300 Message-Id: <20210512174914.10549-3-aardelean@deviqon.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210512174914.10549-1-aardelean@deviqon.com> References: <20210512174914.10549-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 Wed May 12 17:49:05 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandru Ardelean X-Patchwork-Id: 12254453 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,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 29D53C433B4 for ; Wed, 12 May 2021 18:21:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DB230613FB for ; Wed, 12 May 2021 18:21:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242718AbhELSWD (ORCPT ); Wed, 12 May 2021 14:22:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50468 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350521AbhELRvK (ORCPT ); Wed, 12 May 2021 13:51:10 -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 4F344C06138F for ; Wed, 12 May 2021 10:50:00 -0700 (PDT) Received: by mail-ej1-x634.google.com with SMTP id c20so845309ejm.3 for ; Wed, 12 May 2021 10:50:00 -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=SYDiblT/FKbuA+P5DtK7LLEjtQVRy9buQ9rlNnDPTNyrJ6fCURA7APFNkba9LrMETA cp3y5kAVDg7FK34ik232iLoQpAG5Vp1LMM0FdeDtuaNFTN+91XFonJ9BJZWNrqPEGgPa h6sV98fIZv24fN/XvrB0Zl5JgWBVZ/c4dc9RYJsSoQQwzbnJnrKMF67YsAoTvYTGUFf8 8fwD+RyHyj1pUkVk0vJC6sT4gB2u3ZhkssdBvugnvV2eK955YM7zcrQ5hJsHYwpHNaXy 3ieX3bz92AFTz9y6vERaW/F6Sgc8Ba31m5jd1csiSZupR98LhBfDBDUd/dSSY+l7zwQU EoJw== 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=L+mpV0vBAl3fzm/G1318KedmzDyDmlMsmbYlbKAi9qnXRWFcmf4diCAzmiDjTepu9S 1WxC5TbIZH0DIrVL4T/79Vw8TjAq+LG9hG/ipysvPo3f3zYcvLMDaLfy7BGXs+1DjJHH xGepl6Us//WPdhaXnkUdCWaNb8ocBoy/dWBZdyd8hFG93lTJ34fMSRmlauX+VcCC/fZn NOuaUL1gGhvMLtyOaa08W6WsKqND4q5pgoIJScMWUT4oiRQ+Du7NkdeiGAjsewshGuRo dbPjQLZYywhdmQg4KuxacFRqODTRrf3/2Jy3pngWwBoXACPbKaQ/4kAeA9owizYlXWrV a70w== X-Gm-Message-State: AOAM531BNWiFi5RFtyYc32ffscR0MklWNXgdMtHTpOeTJQqNP9fvB9D1 OLDclVD3eHQJUenkn+X+SBaVJy9yA5h3OA== X-Google-Smtp-Source: ABdhPJwBLSV+hsZcozcVFIQf+ebEzlkp5nvvKcSNKrmg6v9FLDS+ICiZXI3Q+Kw2xiIZ/PF/gA6lCg== X-Received: by 2002:a17:906:d978:: with SMTP id rp24mr39245712ejb.333.1620841798809; Wed, 12 May 2021 10:49:58 -0700 (PDT) Received: from neptune.. ([5.2.193.191]) by smtp.gmail.com with ESMTPSA id r16sm338058edq.87.2021.05.12.10.49.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 May 2021 10:49:58 -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 v3 03/12] iio: adc: ad7192: Avoid disabling a clock that was never enabled. Date: Wed, 12 May 2021 20:49:05 +0300 Message-Id: <20210512174914.10549-4-aardelean@deviqon.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210512174914.10549-1-aardelean@deviqon.com> References: <20210512174914.10549-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 Wed May 12 17:49:06 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandru Ardelean X-Patchwork-Id: 12254455 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,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 3F334C43616 for ; Wed, 12 May 2021 18:21:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0733A613EE for ; Wed, 12 May 2021 18:21:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242730AbhELSWE (ORCPT ); Wed, 12 May 2021 14:22:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50504 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350558AbhELRvT (ORCPT ); Wed, 12 May 2021 13:51:19 -0400 Received: from mail-ej1-x62c.google.com (mail-ej1-x62c.google.com [IPv6:2a00:1450:4864:20::62c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0C239C061344 for ; Wed, 12 May 2021 10:50:01 -0700 (PDT) Received: by mail-ej1-x62c.google.com with SMTP id m12so36286477eja.2 for ; Wed, 12 May 2021 10:50:01 -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=qwgFY4dtpVnvZvR2NIXhU4/dNeZKtIuNiLjrbd0tG/g=; b=CfjtKtYnl6pLp9mE+U9cHQVW3tY+tJs7W1r4YQRDsDC/ZFQuoJ2l7PFDP0J34vlyGM mG45ua7MxBM6MQSx0C0C7mCPiq6QyGgrOTPiyNanSenMaENLSFNgOK0qZGUf50SgjWWh FsTfkaVfgwOf+vAAXmBwsIyjiJpAew2ZVSx4iiE8iQZ7poi2LPDP91Vtt0Dy2mAQRQhd RNcfZefx3tT9uwb/TucUu3ZWKHdG8+cfDVLAx6CwtFcuvWkGQKCJeNfkQd5gIjO6RU/L n+j1NqxU+FIiR1qWhzjuyvP3icspsfJ3F2rZws70XjqL25SGKaUnHf2fy1p39izGfj+t MfXg== 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=qwgFY4dtpVnvZvR2NIXhU4/dNeZKtIuNiLjrbd0tG/g=; b=LeC5zzOuwA5c33pzpa1i74ksRkc+Gv03jMALTsTxo/NP3egS2+XBETJ1bsaxnfh8BZ GTKFYtG7pIpf+ELbrIu/nBFAN5n9Nlc5JCu0o0RPk+TXoFY/v28eDxrbw9C11FLVHibX t7Z5EEpxU7uVDlNrdqvbza5LyXoGA1hx0kHx9RL+QCfmW3wzMRPqzEar0Xt0xia51dTO sLSdMLJ6zpP8vnWlJEY2tVa3aUsHwVCPWYztpj7qMykP55SIGbLiNE8VfOWl7NaS0gIp rzCWgTlYMsAOkBNnDeDP4SxQAXOEdo9LBehy3oUn9Ek0AhP/5fBDk8uOwEv/lkbWGs59 UK2Q== X-Gm-Message-State: AOAM531qJDv0Qzh37nyVmfQigGLOXIQOe41InSlnEXeaEkKkhtOJXQ4W f5LgATWsOQZXwivp0gyAl+g949jssa0How== X-Google-Smtp-Source: ABdhPJw3LIhAhbs8K7dfFg2wviOdvE0mWStLp1zDjmP4Lex7PH9Q9OCjg/37Op3sB653ZSk0Wb8WjA== X-Received: by 2002:a17:907:3e28:: with SMTP id hp40mr16146685ejc.523.1620841800033; Wed, 12 May 2021 10:50:00 -0700 (PDT) Received: from neptune.. ([5.2.193.191]) by smtp.gmail.com with ESMTPSA id r16sm338058edq.87.2021.05.12.10.49.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 May 2021 10:49:59 -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 v3 04/12] iio: adc: ad7192: handle zero Avdd regulator value Date: Wed, 12 May 2021 20:49:06 +0300 Message-Id: <20210512174914.10549-5-aardelean@deviqon.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210512174914.10549-1-aardelean@deviqon.com> References: <20210512174914.10549-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 for a zero regulator value, the driver would exit early, initializing the driver only partially. The driver would be in an unknown state. If the regulator value is zero, then the internal reference will be zero (though that value will be zero for anything less than 1 millivolt). Fixes: ab0afa65bbc7 ("staging: iio: adc: ad7192: fail probe on get_voltage") Cc: Alexandru Tachici Signed-off-by: Alexandru Ardelean --- drivers/iio/adc/ad7192.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/iio/adc/ad7192.c b/drivers/iio/adc/ad7192.c index d3be67aa0522..9da394ad3868 100644 --- a/drivers/iio/adc/ad7192.c +++ b/drivers/iio/adc/ad7192.c @@ -951,7 +951,7 @@ static int ad7192_probe(struct spi_device *spi) voltage_uv = regulator_get_voltage(st->avdd); - if (voltage_uv > 0) { + if (voltage_uv >= 0) { st->int_vref_mv = voltage_uv / 1000; } else { ret = voltage_uv; From patchwork Wed May 12 17:49:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandru Ardelean X-Patchwork-Id: 12254457 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,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 5627BC43611 for ; Wed, 12 May 2021 18:21:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 295C1613CB for ; Wed, 12 May 2021 18:21:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242742AbhELSWG (ORCPT ); Wed, 12 May 2021 14:22:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50506 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350563AbhELRvU (ORCPT ); Wed, 12 May 2021 13:51:20 -0400 Received: from mail-ed1-x52d.google.com (mail-ed1-x52d.google.com [IPv6:2a00:1450:4864:20::52d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D1171C061346 for ; Wed, 12 May 2021 10:50:02 -0700 (PDT) Received: by mail-ed1-x52d.google.com with SMTP id f1so5866203edt.4 for ; Wed, 12 May 2021 10:50:02 -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=tAF0dx62soQ3Hr07KE+4fu6mDVXedc1leoQ4lZm5LT0qABOkJkI/YMs6BmzidWJVuc jvHaNqN2hMGLYA+qynnoN1kbH9wCtwI+O10AIPGINml6V+EXzFJ88Mo8Z3YwEAWAXu4t AMN2Bels0YkMrcdTvaxjpd54fmkW+QXWl3mrk788mYjcpMQlJ1al0yYt7ZBwedUKRM7j ORmNH/ceAxITCaDa4N0LThC/v7/OK0gIL6sI0hLS0CY3NwksLxlzuOOXHl5opTxGze3p GU158zyamltw6HxCZvnx2pzglrLKG6mS30c5b0IH/HmFLv6GgXWi/EGF4Uek2JIjjsGj Qhdw== 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=WNQDeoK7Ch7M+1hBV88WFVLuiqDqMrqeKSN37CkqXAgDPXXAuqGY45A80rAu3QRkCs bIt8MXv+ACTE3rfP3k3StgDr1erBAeqqvrVnO7ShitJk4kW0+YJpUAVkj5B4NE6y3kvp Gy6RdQT1Sub4Qbi4dei8LqwubKKgE1RTuiAd7iJfy133BQ8nKTAsZ/4dTrajsjF/NCX4 WCFn84Dl2SKGJYR3j4faCc/HuSIhsb3x0hjq+EkLKUi3t7my+N2I92gsLkYZRYsUgWdu EU59jfyJp1dlsjwEIUSR/bayTI41CeRycr53di6XHLnYLVK6/Nlyc7yv4y4wvbgycxq3 dSfg== X-Gm-Message-State: AOAM530K4XaBr6i90wr+bVwHG2du3gw77nSZHji6/Iyrckfe+wsgaBed cAbj3cPdNQTIX/TDZ6ruYCdV3OGalNuQ8Q== X-Google-Smtp-Source: ABdhPJy/lJaBxi2X3NQ269eKCy1E36c09nNh9XhZs9AjxR9E1UcmCj/5UYQO2CygU1ZsJ4uhrXkkhw== X-Received: by 2002:a05:6402:1b1e:: with SMTP id by30mr9936102edb.277.1620841801295; Wed, 12 May 2021 10:50:01 -0700 (PDT) Received: from neptune.. ([5.2.193.191]) by smtp.gmail.com with ESMTPSA id r16sm338058edq.87.2021.05.12.10.50.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 May 2021 10:50:00 -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 v3 05/12] iio: adc: ad_sigma_delta: introduct devm_ad_sd_setup_buffer_and_trigger() Date: Wed, 12 May 2021 20:49:07 +0300 Message-Id: <20210512174914.10549-6-aardelean@deviqon.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210512174914.10549-1-aardelean@deviqon.com> References: <20210512174914.10549-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 Wed May 12 17:49:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandru Ardelean X-Patchwork-Id: 12254463 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,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 5E0FCC43462 for ; Wed, 12 May 2021 18:21:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2521D613BD for ; Wed, 12 May 2021 18:21:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242754AbhELSWH (ORCPT ); Wed, 12 May 2021 14:22:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50552 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350644AbhELRvc (ORCPT ); Wed, 12 May 2021 13:51:32 -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 EA031C061348 for ; Wed, 12 May 2021 10:50:03 -0700 (PDT) Received: by mail-ej1-x62f.google.com with SMTP id k10so5029305ejj.8 for ; Wed, 12 May 2021 10:50:03 -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=TIuDBj9+Wl3PBpUhmQceJSzOzKrL/yVfsJliiz8NkMiRJudbmV2ZeuG44Wrj45LkVA b0NCwfxKEXI1EE4bb+NGLreQLAs9SN85fwzrwyTXKOwlYTeMfuObbUjIjvjhX7ibi73n pUqrHiY20bVeXJt49/R2fEOOvSLc3KnfdXrWonnkk77Hf4pt9b82OxKbAmwog99ZJUJY 8xGU7Yf3/kfE20MiQ68dT5w6NKZEyIyB0qglQ73Lh2o79fib2kqwpVlHfnOleFQGEIEx OIcn4u+Krev0dBw3p7EB+PVIVJAlBgSxgKPF0al+UOq1ZC4QWJZy3K9S1Xwg6/dWiGWW AY7A== 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=IJp7MlIHII93GLie4ae5g59PoRsPZtvfiNKVyECOdWCHyhcI6SK7W5LT/SBYkctfss KGZB9oJT62YoXZheKFs0/vjtvDWS3TONCmkeMZ4YB+vUXLBHiThJ7/57jh7pXDuQ5clo 0IACO5NSECQJjC6BMEz7lOlNUezT/8AOT4RXoOwF8yi5cHdIlDeGjE6KsixWZQDGFj7h cqc4aupO6QaXthtqZJ5Hjiczhuv2jaXqOa2jvGuzFLtJCKyVGNeDNiSs7ec8IWRkW7v5 7BZuhwOtgzITgNx1JZIabsu5cZC/1MZCQoH/nLYEZahNq9LoktGDDURT5i4LQEe+rqr8 NEeQ== X-Gm-Message-State: AOAM530H84leoXBeWmIj94QrYZljOo/QqB2X9B9WHu5NBpXhfEZGGipZ 15N05rvmgorbUJ+gKOdeD5Lfv7MW/gd/Yw== X-Google-Smtp-Source: ABdhPJxi4Ns2UuaZ8/IGW8hNLNe8K5WE5m2440Ubsgt/9+wNDOKDqoyUynbgEwY8SZIdm9JVH1Zxrw== X-Received: by 2002:a17:906:d9c1:: with SMTP id qk1mr33965044ejb.412.1620841802461; Wed, 12 May 2021 10:50:02 -0700 (PDT) Received: from neptune.. ([5.2.193.191]) by smtp.gmail.com with ESMTPSA id r16sm338058edq.87.2021.05.12.10.50.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 May 2021 10:50:02 -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 v3 06/12] iio: adc: ad7793: convert to device-managed functions Date: Wed, 12 May 2021 20:49:08 +0300 Message-Id: <20210512174914.10549-7-aardelean@deviqon.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210512174914.10549-1-aardelean@deviqon.com> References: <20210512174914.10549-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 Wed May 12 17:49:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandru Ardelean X-Patchwork-Id: 12254459 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,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 7EE33C43617 for ; Wed, 12 May 2021 18:21:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 42F85613D3 for ; Wed, 12 May 2021 18:21:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242780AbhELSWL (ORCPT ); Wed, 12 May 2021 14:22:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50556 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350645AbhELRvc (ORCPT ); Wed, 12 May 2021 13:51:32 -0400 Received: from mail-ej1-x62c.google.com (mail-ej1-x62c.google.com [IPv6:2a00:1450:4864:20::62c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 11BD1C061349 for ; Wed, 12 May 2021 10:50:05 -0700 (PDT) Received: by mail-ej1-x62c.google.com with SMTP id m12so36286702eja.2 for ; Wed, 12 May 2021 10:50:04 -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=hhn1x2vQQ6eb4bVEjNiOxg3lkBu6xYzPHiUdMvVo5Y/ADD9heZCbeyv80YoxoQI+ap xdhFGIHj2gZ4bBbUrehpEcuOZN/pkyKItAxgzagS2SsJimPbjPu8iHeIK46zLIk9cYAO Zuzcmvxr/jHeEHNfVpJoOe3JSiV38DkXgAULzUDESqBVMGUGd6l19UIRwTJYvjwESlQW QAj7ORydlkU6jQxG/ZYMwu350RWGvCyCfruNabAlYzfMSZz5iN/JuJXVx4jyg93RbKzC r8RJT0QTeaz6Hk52NNbaudYGbJlbglVrv5Xc06b5TptX+9A4oZcAvadQHt7kBge4zMKo MHFw== 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=op3WYV8lnAFde1BAJU+smLSK3NnLlluUDEtraAjcCl3jBZ+JiAt8vqhxOJG/9NYzDF +oQ5IjEFB1aW7vcpxEyjmKgVpnVfUs8QamKHMrjxBIPd3/L8qgRxJHsMO3XP2Wch6Ct3 Fz8T1djEmwMS2w2j/gKAP+0Lg9H3kFRRp8HgXNrwEzUakf4xS3Blbi4EpwdK0wovwFLO kCAsRMIUhcDATWyvb4DyJwbSDRWNIvg6GJxfVbnsx+eLpEAC9Y39glU0P5evr2wilALq W91KsNFJIQyMii9BsD2LLOSVAiJj1KAbTV311UM8RdTetoJfk87zpiXbVzEU125/198B Mi8Q== X-Gm-Message-State: AOAM530yM4SZn5Qo75h4A+JTnDWm25Snl7fEZtCuPaLQSsPgueJ03VHX JogUFIP9rXoFY7Y4xEpCQFYoL9Iu9YwQRg== X-Google-Smtp-Source: ABdhPJwq9q5Iy3AdiO/bj8e11TxUZpVFfHepeUMmr9TRTfrbZmPqFQS4cwQWCM56t2MFqztHGwYBdw== X-Received: by 2002:a17:906:fa19:: with SMTP id lo25mr38246636ejb.394.1620841803592; Wed, 12 May 2021 10:50:03 -0700 (PDT) Received: from neptune.. ([5.2.193.191]) by smtp.gmail.com with ESMTPSA id r16sm338058edq.87.2021.05.12.10.50.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 May 2021 10:50:03 -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 v3 07/12] iio: adc: ad7791: convert to device-managed functions Date: Wed, 12 May 2021 20:49:09 +0300 Message-Id: <20210512174914.10549-8-aardelean@deviqon.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210512174914.10549-1-aardelean@deviqon.com> References: <20210512174914.10549-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 Wed May 12 17:49:10 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandru Ardelean X-Patchwork-Id: 12254461 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,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 B8343C43618 for ; Wed, 12 May 2021 18:21:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7BDEE613BD for ; Wed, 12 May 2021 18:21:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242789AbhELSWM (ORCPT ); Wed, 12 May 2021 14:22:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50722 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350799AbhELRwS (ORCPT ); Wed, 12 May 2021 13:52:18 -0400 Received: from mail-ej1-x635.google.com (mail-ej1-x635.google.com [IPv6:2a00:1450:4864:20::635]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 25BD7C06134C for ; Wed, 12 May 2021 10:50:06 -0700 (PDT) Received: by mail-ej1-x635.google.com with SMTP id l4so36250596ejc.10 for ; Wed, 12 May 2021 10:50:06 -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=g0mM27wtPuRCt6rBjngtsvAOSrPcnf7C/Z7EhpJ0zXwIn23BKQFAUsNFCtqdCY/XTh h0TWgja4t+6wQ5d7kytntR6viEA9iO8pTIRjoDk3h463/FyTbtPZgHy+5sPEZMN0A6FY 0w0cF/J6JarAesGk9Zc8NkfsHL3n1M0b+mWUTIzse6PmegkLdEJ4DDWRrx2C3I7d8NVW /65nqrpWdLsmeVEkz0PP2YRClpX4e6VqXtNBHahYNni+rM/ue7Lh9UzD8+Dh/jJfVFj4 hopnjreFvZdW/vT+VhOCrZNUnobe6WlqZ3b0EenHIcQAkVxP08gFVxsMHp2R6XSggQmm xmSQ== 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=WZfIATLu1560kd/2Mh8l6M37mTasnHWF2GHwyWr6rMoesvPRHiq7kSH5DrJivY7K/z aK0hsCiT9HyfTZmQ/PGmywBHxzlA1InG3W/oglRiUjFsLwNFs1UeVH3B5sSzuoZi7H8z HCLpkLjBpD34oTIHwCnP+/SYIO7D8PjYFjyuDgoUlYvxtUblyKRy1DDkBxVxd0FL9eX2 OHoGnOkmelSIR/7dUeJsphxGr4Gsuh9Z+E9vNkU3DhVl6uwwE7mw2TtySF+r5EWo4I7O UR3XfwcAJ0tjAk36IHGz8BMTJUUh1sY6jpKACnTttTynF2uXkpcEhOlz8xE9AklZmAJT rIsA== X-Gm-Message-State: AOAM5300vcCXaU4j2kjfF00rbOH1QUpnshRsFbzEuceI8WBW53VAP0q3 tO3cEc5yVijGK+hF8ayxrB0Uus2xWPQ4Iw== X-Google-Smtp-Source: ABdhPJxfBub/JbH4fkULgPfA6bjBJQqFm3EveARM0tNtexC6e+Td6lKU1VLpOfABtCh+fADbMukCXA== X-Received: by 2002:a17:906:82cb:: with SMTP id a11mr39225121ejy.213.1620841804642; Wed, 12 May 2021 10:50:04 -0700 (PDT) Received: from neptune.. ([5.2.193.191]) by smtp.gmail.com with ESMTPSA id r16sm338058edq.87.2021.05.12.10.50.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 May 2021 10:50:04 -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 v3 08/12] iio: adc: ad7780: convert to device-managed functions Date: Wed, 12 May 2021 20:49:10 +0300 Message-Id: <20210512174914.10549-9-aardelean@deviqon.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210512174914.10549-1-aardelean@deviqon.com> References: <20210512174914.10549-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 Wed May 12 17:49:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandru Ardelean X-Patchwork-Id: 12254465 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,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 5CD13C433B4 for ; Wed, 12 May 2021 18:22:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 16B34613C3 for ; Wed, 12 May 2021 18:22:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242796AbhELSWP (ORCPT ); Wed, 12 May 2021 14:22:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50794 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350904AbhELRwi (ORCPT ); Wed, 12 May 2021 13:52:38 -0400 Received: from mail-ej1-x630.google.com (mail-ej1-x630.google.com [IPv6:2a00:1450:4864:20::630]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3749EC06134F for ; Wed, 12 May 2021 10:50:07 -0700 (PDT) Received: by mail-ej1-x630.google.com with SMTP id t4so36323140ejo.0 for ; Wed, 12 May 2021 10:50:07 -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=xBvo4n1b1lpFvoXyiJXHa/MxZkZ+cVEgHQDwczdnQoM=; b=KeUHS+sM1e7FnHAfkAJ7Aol2WcEZSwD8dAOWuCv5Qvd6OzIRoGIRKTn8gqDF0uDisi bPd0RIbn+h1yOn7ceieEkaop7mFgy478fbu6zPFO6KOFBa5d0RkUH6eTBb5BIyXWSGpz +7/g/2PvfIvNb6kH0/kv5ONgD5oS8UnYRoVOjIgas7m28TfoGkvwsQWi0oH0r9PBkgSh 51WKUnD2amNa/ATxdUfAaZr1wP+nBbYOnxry6jKDGOXQJu4fCtDChSPKy4QFWxVi3INZ 7fGtyvLH0aQd+2jabyC9ZfHcnpTYw/50fcvrrJZdCLx5ricC7WAnxZ50AJh2Ffsw6fZq 8M8Q== 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=xBvo4n1b1lpFvoXyiJXHa/MxZkZ+cVEgHQDwczdnQoM=; b=F0mPiGJofrK48Yir2gpKL2lhEtanZDYfGA//ZPIenjhxo10v1aaufPmian1NabLYV8 4i+V4BwxdMeF7dAaJEOnMlch9pQK5ixbvAgugqscCHeRtES8+LylqYRYQsTeqvYFvq+4 Ca2xIpHQkBeMuOIR14zZXtDk2b56HbQyLb9ITSFqsJ8s0gaYeEvW+XtuhwdL2FaGdCeI KhWJZhxUNJmUoLFxKwayc4vnSNOAr05X4bDyFAnfd2ZlORgoXOu2aIf3uXWg7rWZr/mn Ykq2pF7KzjJEIqCBaufwOJOGGxohY6BCqRGtw4F/4couifc4loxAhEChTr6CuEI9cZ3r HCAg== X-Gm-Message-State: AOAM5313uEvtFaawhlADmt+Tjz+iAk7iIsXnywtfk7hUoVmAE17FRfiX IZBfCcq3TdlH4TXKtfsw3fiSypgNluYbgQ== X-Google-Smtp-Source: ABdhPJydkg/jTMyUOet8s5ERY+J4yag6wbwgnKkuWVtiHkJnqAlKM5TCo+BFuBhkjoO7RE9j+lsnBQ== X-Received: by 2002:a17:907:990f:: with SMTP id ka15mr31620660ejc.132.1620841805716; Wed, 12 May 2021 10:50:05 -0700 (PDT) Received: from neptune.. ([5.2.193.191]) by smtp.gmail.com with ESMTPSA id r16sm338058edq.87.2021.05.12.10.50.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 May 2021 10:50:05 -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 v3 09/12] iio: adc: ad7192: use devm_clk_get_optional() for mclk Date: Wed, 12 May 2021 20:49:11 +0300 Message-Id: <20210512174914.10549-10-aardelean@deviqon.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210512174914.10549-1-aardelean@deviqon.com> References: <20210512174914.10549-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 9da394ad3868..c3442e9aa9fd 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 { @@ -981,8 +981,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 Wed May 12 17:49:12 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandru Ardelean X-Patchwork-Id: 12254471 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,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 64A7FC43461 for ; Wed, 12 May 2021 18:22:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3105D613D6 for ; Wed, 12 May 2021 18:22:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242848AbhELSWR (ORCPT ); Wed, 12 May 2021 14:22:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50464 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350991AbhELRw6 (ORCPT ); Wed, 12 May 2021 13:52:58 -0400 Received: from mail-ej1-x633.google.com (mail-ej1-x633.google.com [IPv6:2a00:1450:4864:20::633]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8930DC061355 for ; Wed, 12 May 2021 10:50:08 -0700 (PDT) Received: by mail-ej1-x633.google.com with SMTP id b25so36190112eju.5 for ; Wed, 12 May 2021 10:50:08 -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=xFkHVHDvpM4JyC3RFUTwL0ulXU8LKKn0HJTf8peIPYk=; b=D3ReImWGwbW1wqo6/tCxCxSe1CGUuqMyKGlsioWYi+ETGeV4gJR3D0VvcCGALUrina UNkNlKikXwVCfMa6rNKkwED8e3HXjFHAHoS5tHxSvBb846wxvA7bAgIDC+xe7b4TrR8Z 1UiXaE8I2fw1SH4GwGA+xAqhyFe7sCcsg43xRIknfwlSAa1Leyiod5s1hxGnRLRtDdem QZDPHI5IEvq3ZMIjjf1a4Tuu2KManRRixupHuU2ZqaNNW6hyKvJpANTsjx/8VA34md3t OnbwvY6YZQxWsxf6OOZDcP9pcvv4/85nHDyzIihEU7ndPzgc/SueuWbnn2UMg/MM5992 Ey5w== 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=xFkHVHDvpM4JyC3RFUTwL0ulXU8LKKn0HJTf8peIPYk=; b=DCNxPV0DDK05V6KlFsLJFSfOUjHBwGyFwRXwvNpb4/Yf8tKBndR6bYdK6FJ1JOKTKS orZ+/xHQF8SJPp2RjebwN7rwLTuGoZCeWDdGnZRttzdQNYsPYOfJMpU04//jEinOVXOF XAZw6oL89nJo4DpIdyPdi+DUJe3sTmt2rMDlATm6e+xJNJt33A5nCA1WmcJd020SKJ4N r0sY029Yi3iVi0f9HH5F2pB2qLfY+dImz2xmClq5U8aEO24I+6QjKmzH3a7peL6x0cht V8CWdWGnC06gkgsyhcyURKThi/Xh77YHUS3MXxnU7J53sypZQbfU0syRuH0ZyTJh3R2M B0uQ== X-Gm-Message-State: AOAM530/cvyRlejyNPK+FWlP25FoDdkT2v4ytfprKrcmHL+6hmlN/jYn kfB+XJIS5ZJBxp6ua8r81IQ5oznKZ1LZyQ== X-Google-Smtp-Source: ABdhPJz8VHCR8NiXBDh+X/OqKT9lhbmZKJqjhxIt05aKwMYjqznKRx3qmWIxLiCB1qlI5n/kfOCb2w== X-Received: by 2002:a17:906:5912:: with SMTP id h18mr38916931ejq.447.1620841806923; Wed, 12 May 2021 10:50:06 -0700 (PDT) Received: from neptune.. ([5.2.193.191]) by smtp.gmail.com with ESMTPSA id r16sm338058edq.87.2021.05.12.10.50.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 May 2021 10:50:06 -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 v3 10/12] iio: adc: ad7192: convert to device-managed functions Date: Wed, 12 May 2021 20:49:12 +0300 Message-Id: <20210512174914.10549-11-aardelean@deviqon.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210512174914.10549-1-aardelean@deviqon.com> References: <20210512174914.10549-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 | 90 ++++++++++++++++------------------------ 1 file changed, 36 insertions(+), 54 deletions(-) diff --git a/drivers/iio/adc/ad7192.c b/drivers/iio/adc/ad7192.c index c3442e9aa9fd..70b7ce70e478 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,36 +947,40 @@ 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) { 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; @@ -975,17 +989,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); @@ -993,55 +1005,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[] = { @@ -1059,7 +1042,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 Wed May 12 17:49:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandru Ardelean X-Patchwork-Id: 12254469 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,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 8B55BC43462 for ; Wed, 12 May 2021 18:22:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 50CCE613CF for ; Wed, 12 May 2021 18:22:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242938AbhELSWV (ORCPT ); Wed, 12 May 2021 14:22:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50072 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351072AbhELRxQ (ORCPT ); Wed, 12 May 2021 13:53:16 -0400 Received: from mail-ej1-x62d.google.com (mail-ej1-x62d.google.com [IPv6:2a00:1450:4864:20::62d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9E34EC061359 for ; Wed, 12 May 2021 10:50:09 -0700 (PDT) Received: by mail-ej1-x62d.google.com with SMTP id c20so845979ejm.3 for ; Wed, 12 May 2021 10:50:09 -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=qXCVU1pOC3NzaTJp9gtolMr27NxdPQPD44yJNa++uNdTnbUbh7ROvboXmUiRoIY863 Pmj++blx5+aTL5eYpceb2RQqLPyFCX9Hxe+OSd1hdjIzo/6B+noo7zTyLZ6IANatMsUk o9KvvT0qdHCyKD7L9+c8BZXRUNOx5ukwp90c4N9oF6P01xGhqIt0VeKuKgBlJq931RsY CswmQnyuXgOMCzhTD8jISNOZOR0kyY4OsLzOj1P0cs0T3RTazIaOJmJA64yJ/N4C7jnk 8yE9iHlGTz/PopQayK/trOQpSF70T/dK1UkqQ7M80FeA2hFD20qAEP1jBZPV5cmT45nK 8czA== 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=VGA7FRq3dMPpD4mrLTPZ2+/vX9IAI/IQoyYj4pHjE+385eOyGFaq6vm2VThsFl6dSe YiJgEzhxtP652CHzMqZAtdQMUkCQx9MNXi1cv+6807wV9UXITZw+6BuE/P7SitNAPisj DRRTZ/e5iqbCEJMAeBHDkdtrsZczIUF4Z5+jDzLHJF5msN0dBZ88i4bfMfVEUtgNP1VJ 66xGs5RfjrYUubnJBH/i0VRhU6FXH+CvaW8uTysLwiloWosF0oCREauAv8YC2H5gI9yW tOs+i+K7aqed1/trUAhYycBNxWcSXZ3uybvdolYyYqyeSzaTAHi+5OnajP2TLaq5Ragz 48tQ== X-Gm-Message-State: AOAM532HNL//pCLHMGu0LtOpjEIoeUuqGJsL4/NcFIe0koYroFs7y0Id Pcgf5CikbBONygXePBJlzVcxtS1SVKYWJw== X-Google-Smtp-Source: ABdhPJxRWOy3CH7rmQIcbkRp4vckxVLhFK/2r4beXIvZ6wPCagZSzLrH0C79YI4iqL1HRTFXCJ5ecA== X-Received: by 2002:a17:906:29ce:: with SMTP id y14mr38621527eje.189.1620841808068; Wed, 12 May 2021 10:50:08 -0700 (PDT) Received: from neptune.. ([5.2.193.191]) by smtp.gmail.com with ESMTPSA id r16sm338058edq.87.2021.05.12.10.50.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 May 2021 10:50:07 -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 v3 11/12] iio: adc: ad7124: Use devm_ managed calls for all of probe() + drop remove() Date: Wed, 12 May 2021 20:49:13 +0300 Message-Id: <20210512174914.10549-12-aardelean@deviqon.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210512174914.10549-1-aardelean@deviqon.com> References: <20210512174914.10549-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 Wed May 12 17:49:14 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandru Ardelean X-Patchwork-Id: 12254467 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=-15.9 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,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 4EC5DC433ED for ; Wed, 12 May 2021 18:22:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 10EB5600D4 for ; Wed, 12 May 2021 18:22:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242888AbhELSWS (ORCPT ); Wed, 12 May 2021 14:22:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50504 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351070AbhELRxQ (ORCPT ); Wed, 12 May 2021 13:53:16 -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 BCD72C06135A for ; Wed, 12 May 2021 10:50:10 -0700 (PDT) Received: by mail-ej1-x632.google.com with SMTP id c22so8142146ejd.12 for ; Wed, 12 May 2021 10:50:10 -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=e10xmBpzys9TdMzE0pnZOOkSfhsx/x+C1dbrHUZpxwE97NttSHDWv5JMPPQzRHCKmf 5q3wJ5nmq/nooxGb8mVQgNDjWMrYDglBaVpSrsIn1rcHqC7bLMzlUR1K9d0aSDaxANMN 8MDIr7L9W2Ama2Do4uMchWdz1vBpNeascHyKnkr+5S7TktkVwvza3oJPN4QniW+C8qwR Wjp3K0jHkZj1hY/NMOCCNUhtWCUzcQbP79tBqyTCMXocF1iEwztNhOFlG8jKbQQwdcqP 4+sEdxNOOqJsRF7tO+rQ/ykf2Fq0Xko9BUwyAfKDYTRVewT8XpjtFLoU9WjFDFSLyjo8 aOTA== 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=iw0MHABBC4O7fooPotyDQVxz6G7+i8ALg/Hwvp+B6iDtcfTuMU9PvD3Uw22CPe3Bwh h3DIeZOlKgrs2oogn7q4C/NNRtwoE9FV+y17HnNK+kj9qbNNek3qIJ5CY1fND/lvSxUx hWyj/+IBrlAenNQBoGn1v6+kKSJLpH38hg8ChRMFAdOzc/6qROoQcyZifMZDnje7aj6z +KyGD4MycJa/52RT0lIyo7XWsNVz6rUhobDsfTILozQSUEZCwOeNL2PI9iupKzYoM6ue KFFXRC+u9VBYa8meHrpBiRuY4EnE9OHUTPJ/ImcbcTMLCypTyTm0xWz1EIzss48Ays/P 9RQQ== X-Gm-Message-State: AOAM530BIZ5900omFw23S/5j4oe/HwefMF/NVjTEpMM6fFKq6vfsIMHU 7TB1JQkexY0NYd5+UAn7GJeSgy/5nO5rJA== X-Google-Smtp-Source: ABdhPJz0FTn0J+EeturXDq+YOEJGN9aS96/Ktldul8oQ4CJTzbrcu1fjcrwMYKn+fa9fVKlSBehKIg== X-Received: by 2002:a17:907:e89:: with SMTP id ho9mr37611483ejc.5.1620841809218; Wed, 12 May 2021 10:50:09 -0700 (PDT) Received: from neptune.. ([5.2.193.191]) by smtp.gmail.com with ESMTPSA id r16sm338058edq.87.2021.05.12.10.50.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 May 2021 10:50:08 -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 v3 12/12] iio: adc: ad_sigma_delta: remove ad_sd_{setup,cleanup}_buffer_and_trigger() Date: Wed, 12 May 2021 20:49:14 +0300 Message-Id: <20210512174914.10549-13-aardelean@deviqon.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210512174914.10549-1-aardelean@deviqon.com> References: <20210512174914.10549-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);