Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp119257pxf; Wed, 10 Mar 2021 01:55:02 -0800 (PST) X-Google-Smtp-Source: ABdhPJzkluGRYCML0NTraURpXfrXJPak57FmkyW2SocA5y3aI9EGBR+6/Fhvq94EvkaZNFkHTyXP X-Received: by 2002:a17:907:2b03:: with SMTP id gc3mr2786889ejc.448.1615370102359; Wed, 10 Mar 2021 01:55:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1615370102; cv=none; d=google.com; s=arc-20160816; b=ZF6UJh+FDZz7VqNYZ17KnIohAasxOgoY/KirqIeHUFlXfL2q2pABwfTCCnWTK/f3BA X26UWGdnlrJKBk5NvYU6TiVSDR5N+tdlmeYNNXKsYXFqtBgeI9kHHm8LSKkXdzuC5QwW cPq2SkSGSbhNJRsEKWU+bq+SLiRTwiKWw+IrrW6mPOXaL5AHwFmY29clTGg5SN3C5Q09 wipCULaOaRxkZ0eOmIlddUV5k/u0+ORDi6EviCcxRUoWQz5s1eqYMxKlEpDevJ5x6ZND Bw546MjPXoCTJbLYT++tA13ffzh8O4W7FurOEFlfZiHB/dx57FwuU10i+cr0QaQTev2l MwlQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=zBIxLdWqLnaTc/HNSK6FC9gib04yK5F64uC+VAu1FBc=; b=OnENK9p6LmBU55DmElvnX1zdtd+RfNp/Tz6CvnHr6KbVfvM/K9t9vGcNlXfBsW+5e7 7xNs6YucvItGDzVzFC0Hb/DusZc9Ad5oMUpAkab4DklcnmpqALHvOj7qNqzWcKJuZJ7P X5ayACFlggUDm8TAz2pmsqk48g+C/2GMgzUhOoxtpoXquyf5Qs/4eRCabbXWPEtAx/OP 7lSqcdF8cchDD7lf0U4T96fI2Tl/z4hJ01ebM9CGtENGXdmjtSPmXYZFX8ChR+YJGDWI 8e1fVKZe8eVgs4S5lg8hXndHvk2NlPrknW7mpeYudTp9C+HoafQrJoT8Yjz0WTtyTKku HFTA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@deviqon.com header.s=google header.b=MSo18LFo; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=deviqon.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id gv19si10732801ejc.109.2021.03.10.01.54.40; Wed, 10 Mar 2021 01:55:02 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@deviqon.com header.s=google header.b=MSo18LFo; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=deviqon.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230397AbhCJJvr (ORCPT + 99 others); Wed, 10 Mar 2021 04:51:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55852 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231139AbhCJJvr (ORCPT ); Wed, 10 Mar 2021 04:51:47 -0500 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 20395C06174A for ; Wed, 10 Mar 2021 01:51:47 -0800 (PST) Received: by mail-ed1-x531.google.com with SMTP id l12so27150358edt.3 for ; Wed, 10 Mar 2021 01:51:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=deviqon.com; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=zBIxLdWqLnaTc/HNSK6FC9gib04yK5F64uC+VAu1FBc=; b=MSo18LFoB3yv54bsMl2QvxGIX+lA2zh3asnEdxzGM5LfyCL6fsQ0E0pcyK2NWxPMEM Kvo/olQLRlSTCgzO/34AYq1Cw9x1u0JGL7sR+2cURgpk4zfljK/7VXp1wTCgaoAoDM4B kJUba0MspCUKqRNov/dSW+DYR6uaB+zDQ/hDvLAWcXjHxYWqVQ296j1ld/D8Px+LhJ8Y 3PQXu40MaR5keFXFs0cflmaL8Wl01y4HNB0ypLbx2PdE/nSbtw/c+5C4bnvNfQ5XZHMG sw+DLP11U4LMaqbV06dJY2hYzS0wJMKc89i5W09HEqUh5dytPuHH/w3rBns5W/zfUGmI Aqng== 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:mime-version :content-transfer-encoding; bh=zBIxLdWqLnaTc/HNSK6FC9gib04yK5F64uC+VAu1FBc=; b=Bcn+/ES2cHCR6n6KvpAH2XlUPhIruL7NU6vQIk/xNYAtKOTchmK5m7WY7oMybUyYBN COBGUojp+YUF7lr9QvHWUNC6VPviVNHMLxBQ0xUb8u1z+iCyj0ZofagXCUdf7Fb2Yy7E oAoq7wpsxRnmcnvBtWXXWCq3sB+MHSaYR+5mXNMwS5IvmQmLny+GT/ms2ZAGosf2tZ23 S9n9dA8egWOBOUZPPAheZnIuthoHcUaY0LR5r/qaI2rV/qkiyUjTUlM70F0oJfXC5O37 UM0yt8hWXeBCbkH/yDMsJ3hCkliM1/oys0eQzZhl9Wh+SveqEh5VzXHyItV7DXyc/VwY cGtA== X-Gm-Message-State: AOAM530zY/2J2kmyf1WaBIZWHRaPezzxkZzUHDjRL0s3lEdQ3jpTiy73 /IdeatYsZsiQESLr5sYIqp3o1Q== X-Received: by 2002:aa7:d74b:: with SMTP id a11mr2301036eds.92.1615369905860; Wed, 10 Mar 2021 01:51:45 -0800 (PST) Received: from localhost.localdomain ([5.2.193.191]) by smtp.gmail.com with ESMTPSA id s20sm8921807ejj.38.2021.03.10.01.51.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Mar 2021 01:51:45 -0800 (PST) From: Alexandru Ardelean To: linux-iio@vger.kernel.org, devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org Cc: Michael.Hennerich@analog.com, gregkh@linuxfoundation.org, linux@deviqon.com, Alexandru Ardelean Subject: [PATCH] staging: iio: ad9834: convert to device-managed functions in probe Date: Wed, 10 Mar 2021 11:51:31 +0200 Message-Id: <20210310095131.47476-1-aardelean@deviqon.com> X-Mailer: git-send-email 2.29.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This change converts the driver to use device-managed functions in the probe function. For the clock and regulator disable, some devm_add_action_or_reset() calls are required, and then devm_iio_device_register() function can be used register the IIO device. The final aim here would be for IIO to export only the device-managed functions of it's API. That's a long way to go and this a small step in that direction. Signed-off-by: Alexandru Ardelean --- drivers/staging/iio/frequency/ad9834.c | 64 +++++++++++++------------- 1 file changed, 31 insertions(+), 33 deletions(-) diff --git a/drivers/staging/iio/frequency/ad9834.c b/drivers/staging/iio/frequency/ad9834.c index 262c3590e64e..b063cfd0e0e1 100644 --- a/drivers/staging/iio/frequency/ad9834.c +++ b/drivers/staging/iio/frequency/ad9834.c @@ -390,6 +390,20 @@ static const struct iio_info ad9833_info = { .attrs = &ad9833_attribute_group, }; +static void ad9834_disable_reg(void *data) +{ + struct regulator *reg = data; + + regulator_disable(reg); +} + +static void ad9834_disable_clk(void *data) +{ + struct clk *clk = data; + + clk_disable_unprepare(clk); +} + static int ad9834_probe(struct spi_device *spi) { struct ad9834_state *st; @@ -407,26 +421,33 @@ static int ad9834_probe(struct spi_device *spi) return ret; } + ret = devm_add_action_or_reset(&spi->dev, ad9834_disable_reg, reg); + if (ret) + return ret; + indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st)); if (!indio_dev) { ret = -ENOMEM; - goto error_disable_reg; + return ret; } - spi_set_drvdata(spi, indio_dev); st = iio_priv(indio_dev); mutex_init(&st->lock); st->mclk = devm_clk_get(&spi->dev, NULL); if (IS_ERR(st->mclk)) { ret = PTR_ERR(st->mclk); - goto error_disable_reg; + return ret; } ret = clk_prepare_enable(st->mclk); if (ret) { dev_err(&spi->dev, "Failed to enable master clock\n"); - goto error_disable_reg; + return ret; } + ret = devm_add_action_or_reset(&spi->dev, ad9834_disable_clk, st->mclk); + if (ret) + return ret; + st->spi = spi; st->devid = spi_get_device_id(spi)->driver_data; st->reg = reg; @@ -470,48 +491,26 @@ static int ad9834_probe(struct spi_device *spi) ret = spi_sync(st->spi, &st->msg); if (ret) { dev_err(&spi->dev, "device init failed\n"); - goto error_clock_unprepare; + return ret; } ret = ad9834_write_frequency(st, AD9834_REG_FREQ0, 1000000); if (ret) - goto error_clock_unprepare; + return ret; ret = ad9834_write_frequency(st, AD9834_REG_FREQ1, 5000000); if (ret) - goto error_clock_unprepare; + return ret; ret = ad9834_write_phase(st, AD9834_REG_PHASE0, 512); if (ret) - goto error_clock_unprepare; + return ret; ret = ad9834_write_phase(st, AD9834_REG_PHASE1, 1024); if (ret) - goto error_clock_unprepare; - - ret = iio_device_register(indio_dev); - if (ret) - goto error_clock_unprepare; - - return 0; -error_clock_unprepare: - clk_disable_unprepare(st->mclk); -error_disable_reg: - regulator_disable(reg); - - return ret; -} - -static int ad9834_remove(struct spi_device *spi) -{ - struct iio_dev *indio_dev = spi_get_drvdata(spi); - struct ad9834_state *st = iio_priv(indio_dev); - - iio_device_unregister(indio_dev); - clk_disable_unprepare(st->mclk); - regulator_disable(st->reg); + return ret; - return 0; + return devm_iio_device_register(&spi->dev, indio_dev); } static const struct spi_device_id ad9834_id[] = { @@ -539,7 +538,6 @@ static struct spi_driver ad9834_driver = { .of_match_table = ad9834_of_match }, .probe = ad9834_probe, - .remove = ad9834_remove, .id_table = ad9834_id, }; module_spi_driver(ad9834_driver); -- 2.29.2