Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2569147pxj; Mon, 10 May 2021 06:07:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy2NSz3BxaKror+KV4XVYcS35MgZrh1/5u+cR7cJTRQ66/61nkgjZpq7r0KRJU77AWQxhvA X-Received: by 2002:a05:6402:36d:: with SMTP id s13mr29640773edw.103.1620652074569; Mon, 10 May 2021 06:07:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620652074; cv=none; d=google.com; s=arc-20160816; b=LS8byLlDkmG3qzuGMgaaUlfxf+i/ihm7w68BlyTcAZjGWQqmRWpjZTe13OMa74K0Wj Zhf89FOtYF3VlgcdO1HbeXGHl2B4507tAxi5lSvBSLUH04a2cfI66CMbrnP6y7+7ZSU6 5j5rWTqIRV30tm8POWQ//75BOs3kipBLMk4XmGgAZpQRfmvC1Syw5gZtHE7RBoaKn4VJ 8sf+3FWmLsA9yKtAVwu4ZreUDKeEYoRaGkYopSKVDCoYImlYY3g81dz2YJalYFWMOzDP xYETxmqzEPs9f4wiIPCPJBFpKlvHnEmAl7os9Dly5VZ4B22hhv7bsTh3BWMzTmS/uOXg o5+w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=T22i+g53k1fhCLKh9tB02Omn3iL2iUzJbrWzhjCB28A=; b=uBStiOAZ+YYoVQ55unv/qlP/i8eDbDAqOl2YbfkdYH+Vy5+IUo44Dij7RFjCN3EU0K +K8xhhVlXbZC7gDdrEVvWK+9doJ+OVGXfdnuB1IedGEQzMhTn5/kYeoT4cd97eC0KJ7o LxiUJ8q+eEdWLuUSEjZY7XwYMlZTW/+EMfKy0U9Fszk/0dDBl/IzVry5chWac4UErHKL yzbxgQtRrDbS5qrUl+J/W9eFXCWhJcYZBvRQQ+zA5tpILbSbfL1jYe1yqoBfGLX/LHNu wHtGJTavp5mBdiV0yeYv2vIr6A/h7TIf5BnPeNV7m6/YVCfillpVnDQ36tNtL4aBsmxw 2GMg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@deviqon.com header.s=google header.b=eCtUxx+Q; 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 a15si15061273edr.192.2021.05.10.06.07.30; Mon, 10 May 2021 06:07:54 -0700 (PDT) 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=eCtUxx+Q; 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 S1351300AbhEJNGF (ORCPT + 99 others); Mon, 10 May 2021 09:06:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44178 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351119AbhEJNC7 (ORCPT ); Mon, 10 May 2021 09:02:59 -0400 Received: from mail-wm1-x32a.google.com (mail-wm1-x32a.google.com [IPv6:2a00:1450:4864:20::32a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 44A11C06134F for ; Mon, 10 May 2021 05:55:53 -0700 (PDT) Received: by mail-wm1-x32a.google.com with SMTP id 82-20020a1c01550000b0290142562ff7c9so8827545wmb.3 for ; Mon, 10 May 2021 05:55:53 -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=eCtUxx+QoNkZtb/x+DkVSPqZKOadIhEMMlPASjY0l/1g2fFi8OVRvbxa1cF2ypMlad Cy5bx2x/k/plI+xFS7PNi3znFYwTD7Wpi2sWEJ/T0lbNvXorIFyFAkzz450CKuleSf+C gU2jWBcQ/3ILNxkS823GfeKdQ/GOhlpkLCdVDW4zVsbdKcBrRJckPits/sj9xHOXy+N+ wjmQXMupfKXoLBd4QOLr1ord6ufgI4xlfjoYD2yoKDSvolyGTYtWtrRIGCsaiJ/NMyTJ fxSymlUL9EG6oNJTcQO4D0zZsX92771UIVWAt8mHt13/SMdZ3ckm5Tp0O9HTlsrnSwsC gjhQ== 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=uGoVqNYzGICmn1rIBoHY0502DeMmWN0XfTSs4SdVWG0IOE/MhwYoNDoMb1PD4HBFLm kbTLwX4Rke5eOZsG5OMWJ0xZga6IcSDla3Z+Xxw8cYVIbNhzVluJoGtEnN4SK07wanZe k/ntwr9aZfR2420l6IbCg3M9p5w5G+P+73RIVJ2W0EmFyKWwtTDCWLM/l2O3AZtgiFeL j9o7cj5AYHJ7NG9HFsYRKNsx/sGVQm3rE7EHyjZwWa8WhfG22LARJHUM5REeM3+YqY4a ndzg2jAPcFpsBWVcpsCPDbRl0ISxjs1KHy4GzEn9BJJ5ybSqLjHacJu7jKHWf5D0pRoT s5wQ== X-Gm-Message-State: AOAM531TgR+qbQJyVafl00vIUaWB5o5KfoYrhPuUAI6fyzF6sXvl/3F6 QW1C2ONB6qjSfVWcI51JhqlyBA== X-Received: by 2002:a05:600c:4304:: with SMTP id p4mr37384148wme.111.1620651352071; Mon, 10 May 2021 05:55:52 -0700 (PDT) Received: from neptune.. ([5.2.193.191]) by smtp.gmail.com with ESMTPSA id n2sm23134329wmb.32.2021.05.10.05.55.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 May 2021 05:55:51 -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 01/11] iio: adc: ad_sigma_delta: introduct devm_ad_sd_setup_buffer_and_trigger() Date: Mon, 10 May 2021 15:55:13 +0300 Message-Id: <20210510125523.1271237-2-aardelean@deviqon.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210510125523.1271237-1-aardelean@deviqon.com> References: <20210510125523.1271237-1-aardelean@deviqon.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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 -- 2.31.1