From patchwork Fri Dec 22 15:07:16 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eugen Hristev X-Patchwork-Id: 10130677 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 529FF60318 for ; Fri, 22 Dec 2017 15:12:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 53CF529FB5 for ; Fri, 22 Dec 2017 15:12:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 48C282A05A; Fri, 22 Dec 2017 15:12:29 +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=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BE86029FB5 for ; Fri, 22 Dec 2017 15:12:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756491AbdLVPL7 (ORCPT ); Fri, 22 Dec 2017 10:11:59 -0500 Received: from esa1.microchip.iphmx.com ([68.232.147.91]:56578 "EHLO esa1.microchip.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756470AbdLVPKP (ORCPT ); Fri, 22 Dec 2017 10:10:15 -0500 X-IronPort-AV: E=Sophos;i="5.45,441,1508828400"; d="scan'208";a="10402498" Received: from smtpout.microchip.com (HELO email.microchip.com) ([198.175.253.82]) by esa1.microchip.iphmx.com with ESMTP/TLS/DHE-RSA-AES256-SHA; 22 Dec 2017 08:10:14 -0700 Received: from eh-station.mchp-main.com (10.10.76.4) by chn-sv-exch07.mchp-main.com (10.10.76.108) with Microsoft SMTP Server id 14.3.352.0; Fri, 22 Dec 2017 08:10:13 -0700 From: Eugen Hristev To: , , , , , , , , , CC: Eugen Hristev Subject: [PATCH 09/14] iio: inkern: triggers: create helpers for OF trigger retrieval Date: Fri, 22 Dec 2017 17:07:16 +0200 Message-ID: <1513955241-10985-10-git-send-email-eugen.hristev@microchip.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1513955241-10985-1-git-send-email-eugen.hristev@microchip.com> References: <1513955241-10985-1-git-send-email-eugen.hristev@microchip.com> MIME-Version: 1.0 Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Create helper API to get trigger information from OF regarding trigger producer/consumer for iio triggers. The functions will search for matching trigger by name, similar with channel retrieval Signed-off-by: Eugen Hristev --- drivers/iio/inkern.c | 91 ++++++++++++++++++++++++++++++++++++ include/linux/iio/trigger_consumer.h | 1 + 2 files changed, 92 insertions(+) diff --git a/drivers/iio/inkern.c b/drivers/iio/inkern.c index 069defc..58bd18d 100644 --- a/drivers/iio/inkern.c +++ b/drivers/iio/inkern.c @@ -14,9 +14,13 @@ #include #include "iio_core.h" +#include "iio_core_trigger.h" #include #include #include +#include +#include + struct iio_map_internal { struct iio_dev *indio_dev; @@ -262,6 +266,39 @@ static struct iio_channel *of_iio_channel_get_all(struct device *dev) return ERR_PTR(ret); } +#ifdef CONFIG_IIO_TRIGGER + +static struct iio_trigger *of_iio_trigger_get(struct device_node *np, int index) +{ + struct device *idev; + struct iio_dev *indio_dev; + int err; + struct of_phandle_args iiospec; + struct iio_trigger *trig; + + err = of_parse_phandle_with_args(np, "io-triggers", + "#io-trigger-cells", + index, &iiospec); + if (err) + return ERR_PTR(err); + + idev = bus_find_device(&iio_bus_type, NULL, iiospec.np, + iio_dev_node_match); + of_node_put(iiospec.np); + if (!idev) + return ERR_PTR(-EPROBE_DEFER); + + indio_dev = dev_to_iio_dev(idev); + + trig = iio_trigger_find_from_device(indio_dev, iiospec.args[0]); + + if (!trig) + return ERR_PTR(-ENODEV); + + return trig; +} +#endif /* CONFIG_IIO_TRIGGER */ + #else /* CONFIG_OF */ static inline struct iio_channel * @@ -275,6 +312,12 @@ static inline struct iio_channel *of_iio_channel_get_all(struct device *dev) return NULL; } +static inline struct iio_trigger *of_iio_trigger_get(struct device_node *np, + int index) +{ + return NULL; +} + #endif /* CONFIG_OF */ static struct iio_channel *iio_channel_get_sys(const char *name, @@ -927,3 +970,51 @@ ssize_t iio_write_channel_ext_info(struct iio_channel *chan, const char *attr, chan->channel, buf, len); } EXPORT_SYMBOL_GPL(iio_write_channel_ext_info); + +#ifdef CONFIG_IIO_TRIGGER +struct iio_trigger *iio_trigger_find(struct device *dev, char *name) +{ + struct device_node *np = dev->of_node; + struct iio_trigger *trig = NULL; + + /* Walk up the tree of devices looking for a matching iio trigger */ + while (np) { + int index = 0; + + /* + * For named iio triggers, first look up the name in the + * "io-trigger-names" property. If it cannot be found, the + * index will be an error code, and of_iio_trigger_get() + * will fail. + */ + if (name) + index = of_property_match_string(np, "io-trigger-names", + name); + trig = of_iio_trigger_get(np, index); + if (!IS_ERR(trig) || PTR_ERR(trig) == -EPROBE_DEFER) { + break; + } else if (name && index >= 0) { + pr_err("ERROR: could not get IIO trigger %pOF:%s(%i)\n", + np, name ? name : "", index); + return trig; + } + + /* + * No matching IIO trigger found on this node. + * If the parent node has a "io-trigger-ranges" property, + * then we can try one of its channels. + */ + np = np->parent; + if (np && !of_get_property(np, "io-trigger-ranges", NULL)) + return trig; + } + + if (!trig || (IS_ERR(trig) && PTR_ERR(trig) != -EPROBE_DEFER)) + dev_dbg(dev, "error retrieving trigger information\n"); + else + dev_dbg(dev, "trigger found: %s\n", name); + + return trig; +} +EXPORT_SYMBOL_GPL(iio_trigger_find); +#endif /* CONFIG_IIO_TRIGGER */ diff --git a/include/linux/iio/trigger_consumer.h b/include/linux/iio/trigger_consumer.h index 13be595..b2fc485 100644 --- a/include/linux/iio/trigger_consumer.h +++ b/include/linux/iio/trigger_consumer.h @@ -62,6 +62,7 @@ irqreturn_t iio_pollfunc_store_time(int irq, void *p); void iio_trigger_notify_done(struct iio_trigger *trig); +struct iio_trigger *iio_trigger_find(struct device *dev, char *name); /* * Two functions for common case where all that happens is a pollfunc * is attached and detached from a trigger