From patchwork Fri Feb 17 16:03:47 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fabrice Gasnier X-Patchwork-Id: 9580303 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 09526600F6 for ; Fri, 17 Feb 2017 16:04:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E985228730 for ; Fri, 17 Feb 2017 16:04:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DA91A28733; Fri, 17 Feb 2017 16:04:51 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 1C35228731 for ; Fri, 17 Feb 2017 16:04:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=NMz72pWKEHqNNrdt6dfS0iVB/hI6cHlpyDxYwDT1DGM=; b=NPu3h1eHTDxL8J 3wrZqiq/72BENr99/9v81vEZ9Aszma2p7xaFIzBEmDr3eD566RLVi8UB18KDocT9l4WzWJD5x/KeC bRtjolI43a4cVahyTwj7vuXKpH93nXQtELt+/BgKNZL8I3RXV2CDocruvm5u0QMJmp/NOr+8b3wOs HMl6K5GNtjCThpB+JCgoN6cFzPxVX/swfNTIE6bVJoP3tQ3aHlx+HcJE8/o5/MElpj4J1YU0cN8wp gt4/1VSF+CIWiQwqj8ZEtcp3dQfCZbDNeOuW/W0uTS4OMJoV6w2iEm4CxcjK3clmLScoYLFLtiaEG zxW1j6unR4Hqv/jpM82Q==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1cel1e-00071L-Ak; Fri, 17 Feb 2017 16:04:50 +0000 Received: from mx08-00178001.pphosted.com ([91.207.212.93] helo=mx07-00178001.pphosted.com) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1cel1a-0006yr-8F for linux-arm-kernel@lists.infradead.org; Fri, 17 Feb 2017 16:04:48 +0000 Received: from pps.filterd (m0046661.ppops.net [127.0.0.1]) by mx08-00178001.pphosted.com (8.16.0.11/8.16.0.11) with SMTP id v1HFxmST007754; Fri, 17 Feb 2017 17:04:04 +0100 Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx08-.pphosted.com with ESMTP id 28ncfhf8p9-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Fri, 17 Feb 2017 17:04:04 +0100 Received: from zeta.dmz-eu.st.com (zeta.dmz-eu.st.com [164.129.230.9]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 391F73A; Fri, 17 Feb 2017 16:04:03 +0000 (GMT) Received: from Webmail-eu.st.com (sfhdag5node3.st.com [10.75.127.15]) by zeta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 158B826E7; Fri, 17 Feb 2017 16:04:03 +0000 (GMT) Received: from localhost (10.75.127.46) by SFHDAG5NODE3.st.com (10.75.127.15) with Microsoft SMTP Server (TLS) id 15.0.1178.4; Fri, 17 Feb 2017 17:04:02 +0100 From: Fabrice Gasnier To: , , , , , Subject: [RFC 2/4] iio: trigger: add OF support Date: Fri, 17 Feb 2017 17:03:47 +0100 Message-ID: <1487347429-31761-3-git-send-email-fabrice.gasnier@st.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1487347429-31761-1-git-send-email-fabrice.gasnier@st.com> References: <1487347429-31761-1-git-send-email-fabrice.gasnier@st.com> MIME-Version: 1.0 X-Originating-IP: [10.75.127.46] X-ClientProxiedBy: SFHDAG1NODE3.st.com (10.75.127.3) To SFHDAG5NODE3.st.com (10.75.127.15) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-02-17_13:, , signatures=0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170217_080446_597216_7A38A723 X-CRM114-Status: UNSURE ( 9.84 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mark.rutland@arm.com, benjamin.gaignard@linaro.org, lars@metafoo.de, alexandre.torgue@st.com, linux-iio@vger.kernel.org, pmeerw@pmeerw.net, mcoquelin.stm32@gmail.com, knaack.h@gmx.de, fabrice.gasnier@st.com, linus.walleij@linaro.org, benjamin.gaignard@st.com Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Provide OF support. Device drivers can get IIO triggers from dt. Introduce IIO trigger specifiers, so there are: - IIO trigger providers, e.g. dt nodes designated with #io-trigger-cells= - IIO trigger consumers, e.g. phandles listed in io-triggers = <...>. Those can be identified by names by using 'io-trigger-names'. Signed-off-by: Fabrice Gasnier --- drivers/iio/industrialio-trigger.c | 100 +++++++++++++++++++++++++++++++++++++ include/linux/iio/trigger.h | 4 ++ 2 files changed, 104 insertions(+) diff --git a/drivers/iio/industrialio-trigger.c b/drivers/iio/industrialio-trigger.c index 978e1592..d3ac33c 100644 --- a/drivers/iio/industrialio-trigger.c +++ b/drivers/iio/industrialio-trigger.c @@ -768,3 +768,103 @@ int iio_triggered_buffer_predisable(struct iio_dev *indio_dev) indio_dev->pollfunc); } EXPORT_SYMBOL(iio_triggered_buffer_predisable); + +#ifdef CONFIG_OF +static int iio_trig_node_match(struct device *dev, void *data) +{ + return dev->of_node == data && dev->type == &iio_trig_type; +} + +static struct iio_trigger *__of_iio_trig_get(struct device_node *np, int index) +{ + struct of_phandle_args trigspec; + struct device *dev; + int err; + + err = of_parse_phandle_with_args(np, "io-triggers", + "#io-trigger-cells", + index, &trigspec); + if (err) + return ERR_PTR(err); + + dev = bus_find_device(&iio_bus_type, NULL, trigspec.np, + iio_trig_node_match); + of_node_put(trigspec.np); + if (dev == NULL) + return ERR_PTR(-EPROBE_DEFER); + + return to_iio_trigger(dev); +} + +static struct iio_trigger *__of_iio_trig_get_by_name(struct device_node *np, + const char *name) +{ + struct iio_trigger *trig; + int index = 0; + + if (!np) + return ERR_PTR(-EINVAL); + if (name) + index = of_property_match_string(np, "io-trigger-names", name); + if (index < 0) + return ERR_PTR(index); + trig = __of_iio_trig_get(np, index); + if (!IS_ERR(trig) || PTR_ERR(trig) == -EPROBE_DEFER) + return trig; + + if (name && index >= 0) + pr_err("ERROR: could not get IIO trigger %s:%s(%i)\n", + np->full_name, name ? name : "", index); + + return ERR_PTR(-ENOENT); +} +#else /* CONFIG_OF */ +static inline struct iio_trigger * +__of_iio_trig_get_by_name(struct device_node *np, const char *name) +{ + return ERR_PTR(-ENOENT); +} +#endif + +struct iio_trigger *iio_trigger_get_by_name(struct device *dev, + const char *name) +{ + struct iio_trigger *trig; + + if (!dev) + return ERR_PTR(-EINVAL); + + trig = __of_iio_trig_get_by_name(dev->of_node, name); + if (!IS_ERR(trig)) + return iio_trigger_get(trig); + + return trig; +} +EXPORT_SYMBOL_GPL(iio_trigger_get_by_name); + +static void devm_iio_trigger_put(struct device *dev, void *res) +{ + iio_trigger_put(*(struct iio_trigger **)res); +} + +struct iio_trigger *devm_iio_trigger_get_by_name(struct device *dev, + const char *name) +{ + struct iio_trigger **ptr, *trig; + + ptr = devres_alloc(devm_iio_trigger_put, sizeof(*ptr), GFP_KERNEL); + if (!ptr) + return ERR_PTR(-ENOMEM); + + trig = iio_trigger_get_by_name(dev, name); + if (IS_ERR(trig)) { + devres_free(ptr); + return trig; + } + + *ptr = trig; + devres_add(dev, ptr); + + return trig; +} +EXPORT_SYMBOL_GPL(devm_iio_trigger_get_by_name) diff --git a/include/linux/iio/trigger.h b/include/linux/iio/trigger.h index ea08302..1f1ec20 100644 --- a/include/linux/iio/trigger.h +++ b/include/linux/iio/trigger.h @@ -173,6 +173,10 @@ void devm_iio_trigger_unregister(struct device *dev, int iio_trigger_validate_own_device(struct iio_trigger *trig, struct iio_dev *indio_dev); +struct iio_trigger *iio_trigger_get_by_name(struct device *dev, + const char *name); +struct iio_trigger *devm_iio_trigger_get_by_name(struct device *dev, + const char *name); #else struct iio_trigger; struct iio_trigger_ops;