From patchwork Fri Dec 22 15:07:12 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eugen Hristev X-Patchwork-Id: 10130695 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 E78C060318 for ; Fri, 22 Dec 2017 15:13:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E939F2A044 for ; Fri, 22 Dec 2017 15:13:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DE2AA2A065; Fri, 22 Dec 2017 15:13:17 +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 94AF62A044 for ; Fri, 22 Dec 2017 15:13:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756615AbdLVPNB (ORCPT ); Fri, 22 Dec 2017 10:13:01 -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 S1756291AbdLVPKF (ORCPT ); Fri, 22 Dec 2017 10:10:05 -0500 X-IronPort-AV: E=Sophos;i="5.45,441,1508828400"; d="scan'208";a="10402484" 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:02 -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:01 -0700 From: Eugen Hristev To: , , , , , , , , , CC: Eugen Hristev Subject: [PATCH 05/14] iio: triggers: add helper function to retrieve trigger Date: Fri, 22 Dec 2017 17:07:12 +0200 Message-ID: <1513955241-10985-6-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-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Add a helper function that will retrieve a trigger by index from a device. This is intended to be used in trigger consumer drivers. Signed-off-by: Eugen Hristev --- drivers/iio/iio_core_trigger.h | 21 +++++++++++++++++++++ drivers/iio/industrialio-trigger.c | 23 +++++++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/drivers/iio/iio_core_trigger.h b/drivers/iio/iio_core_trigger.h index 1fdb1e4..14c4253 100644 --- a/drivers/iio/iio_core_trigger.h +++ b/drivers/iio/iio_core_trigger.h @@ -21,6 +21,15 @@ void iio_device_register_trigger_consumer(struct iio_dev *indio_dev); **/ void iio_device_unregister_trigger_consumer(struct iio_dev *indio_dev); +/** + * iio_trigger_find_from_device() - get the trigger from the device having the + * index given. + * @indio_dev: iio_dev where to get the trigger from + * @index: the index of the trigger to retrieve + **/ +__maybe_unused struct iio_trigger * +iio_trigger_find_from_device(struct iio_dev *indio_dev, u32 index); + #else /** @@ -40,4 +49,16 @@ static void iio_device_unregister_trigger_consumer(struct iio_dev *indio_dev) { } +/** + * iio_trigger_find_from_device() - get the trigger from the device having the + * index given. + * @indio_dev: iio_dev where to get the trigger from + * @index: the index of the trigger to retrieve + **/ +static __maybe_unused struct iio_trigger * +iio_trigger_find_from_device(struct iio_dev *indio_dev, u32 index) +{ + return NULL; +} + #endif /* CONFIG_TRIGGER_CONSUMER */ diff --git a/drivers/iio/industrialio-trigger.c b/drivers/iio/industrialio-trigger.c index ce66699..cbaa079 100644 --- a/drivers/iio/industrialio-trigger.c +++ b/drivers/iio/industrialio-trigger.c @@ -134,6 +134,29 @@ int iio_trigger_set_immutable(struct iio_dev *indio_dev, struct iio_trigger *tri } EXPORT_SYMBOL(iio_trigger_set_immutable); +/* Find the trigger from the given device corresponding to given index */ +struct __maybe_unused iio_trigger * +iio_trigger_find_from_device(struct iio_dev *indio_dev, u32 index) +{ + struct iio_trigger *iter, *trig = NULL; + u32 i = 0; + + mutex_lock(&iio_trigger_list_lock); + + list_for_each_entry(iter, &iio_trigger_list, list) { + if (!iio_trigger_validate_own_device(iter, indio_dev)) { + if (i == index) { + trig = iter; + break; + } + i++; + } + } + mutex_unlock(&iio_trigger_list_lock); + + return trig; +} + /* Search for trigger by name, assuming iio_trigger_list_lock held */ static struct iio_trigger *__iio_trigger_find_by_name(const char *name) {