From patchwork Mon Jan 30 14:33:59 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fabrice Gasnier X-Patchwork-Id: 9545517 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 525A260425 for ; Mon, 30 Jan 2017 14:37:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4B99D26E97 for ; Mon, 30 Jan 2017 14:37:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4089B2811E; Mon, 30 Jan 2017 14:37:25 +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 autolearn=unavailable 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 BCB6926E97 for ; Mon, 30 Jan 2017 14:37:24 +0000 (UTC) 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 1cYD59-0008NC-MY; Mon, 30 Jan 2017 14:37:23 +0000 Received: from mx07-00178001.pphosted.com ([62.209.51.94]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1cYD2j-0004qg-Pc for linux-arm-kernel@lists.infradead.org; Mon, 30 Jan 2017 14:35:10 +0000 Received: from pps.filterd (m0046037.ppops.net [127.0.0.1]) by m0046037.ppops.net (8.16.0.11/8.16.0.11) with SMTP id v0UETerT032523; Mon, 30 Jan 2017 15:34:20 +0100 Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-.pphosted.com with ESMTP id 288hxw1qum-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Mon, 30 Jan 2017 15:34:20 +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 D50A038; Mon, 30 Jan 2017 14:34:19 +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 A59F02A20; Mon, 30 Jan 2017 14:34:19 +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; Mon, 30 Jan 2017 15:34:19 +0100 From: Fabrice Gasnier To: , , , , , Subject: [PATCH v2 4/5] iio: trigger: add support for STM32 EXTI triggers Date: Mon, 30 Jan 2017 15:33:59 +0100 Message-ID: <1485786840-4557-5-git-send-email-fabrice.gasnier@st.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1485786840-4557-1-git-send-email-fabrice.gasnier@st.com> References: <1485786840-4557-1-git-send-email-fabrice.gasnier@st.com> MIME-Version: 1.0 X-Originating-IP: [10.75.127.46] X-ClientProxiedBy: SFHDAG2NODE2.st.com (10.75.127.5) To SFHDAG5NODE3.st.com (10.75.127.15) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-01-30_08:, , signatures=0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170130_063454_592428_7D86AD74 X-CRM114-Status: GOOD ( 22.16 ) 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, 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 EXTi[0..15] gpio signal can be routed internally as trigger source for ADC or DAC conversions. Configure them as interrupts to configure trigger path in HW. Note: interrupt handler isn't required here, and corresponding interrupt can be kept masked at exti controller level. Signed-off-by: Fabrice Gasnier --- drivers/iio/trigger/Kconfig | 11 +++ drivers/iio/trigger/Makefile | 1 + drivers/iio/trigger/stm32-exti-trigger.c | 124 +++++++++++++++++++++++++ include/linux/iio/trigger/stm32-exti-trigger.h | 26 ++++++ 4 files changed, 162 insertions(+) create mode 100644 drivers/iio/trigger/stm32-exti-trigger.c create mode 100644 include/linux/iio/trigger/stm32-exti-trigger.h diff --git a/drivers/iio/trigger/Kconfig b/drivers/iio/trigger/Kconfig index e4d4e63..3fbf90c 100644 --- a/drivers/iio/trigger/Kconfig +++ b/drivers/iio/trigger/Kconfig @@ -24,6 +24,17 @@ config IIO_INTERRUPT_TRIGGER To compile this driver as a module, choose M here: the module will be called iio-trig-interrupt. +config IIO_STM32_EXTI_TRIGGER + tristate "STM32 EXTI Trigger" + depends on (ARCH_STM32 && OF) || COMPILE_TEST + select STM32_EXTI + help + Select this option to enable STM32 EXTI Triggers on GPIO. These + maybe used then on other STM32 IPs like ADC or DAC. + + To compile this driver as a module, choose M here: the + module will be called stm32-exti-trigger. + config IIO_STM32_TIMER_TRIGGER tristate "STM32 Timer Trigger" depends on (ARCH_STM32 && OF && MFD_STM32_TIMERS) || COMPILE_TEST diff --git a/drivers/iio/trigger/Makefile b/drivers/iio/trigger/Makefile index 5c4ecd3..12d5d72 100644 --- a/drivers/iio/trigger/Makefile +++ b/drivers/iio/trigger/Makefile @@ -6,6 +6,7 @@ obj-$(CONFIG_IIO_HRTIMER_TRIGGER) += iio-trig-hrtimer.o obj-$(CONFIG_IIO_INTERRUPT_TRIGGER) += iio-trig-interrupt.o +obj-$(CONFIG_IIO_STM32_EXTI_TRIGGER) += stm32-exti-trigger.o obj-$(CONFIG_IIO_STM32_TIMER_TRIGGER) += stm32-timer-trigger.o obj-$(CONFIG_IIO_SYSFS_TRIGGER) += iio-trig-sysfs.o obj-$(CONFIG_IIO_TIGHTLOOP_TRIGGER) += iio-trig-loop.o diff --git a/drivers/iio/trigger/stm32-exti-trigger.c b/drivers/iio/trigger/stm32-exti-trigger.c new file mode 100644 index 0000000..2a3ec3c --- /dev/null +++ b/drivers/iio/trigger/stm32-exti-trigger.c @@ -0,0 +1,124 @@ +/* + * Copyright (C) 2017, STMicroelectronics - All Rights Reserved + * Author: Fabrice Gasnier . + * + * License type: GPLv2 + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 as published by + * the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + */ + +#include +#include +#include +#include +#include +#include + +/* STM32 has up to 16 EXTI triggers on GPIOs */ +#define STM32_MAX_EXTI_TRIGGER 16 + +static const struct iio_trigger_ops exti_trigger_ops = { + .owner = THIS_MODULE, +}; + +bool is_stm32_exti_trigger(struct iio_trigger *trig) +{ + return (trig->ops == &exti_trigger_ops); +} +EXPORT_SYMBOL(is_stm32_exti_trigger); + +static irqreturn_t stm32_exti_trigger_handler(int irq, void *data) +{ + /* Exti handler shouldn't be invoked, and isn't used */ + return IRQ_HANDLED; +} + +static int stm32_exti_trigger_probe(struct platform_device *pdev) +{ + int irq, ret; + char name[8]; + struct gpio_desc *gpio; + struct iio_trigger *trig; + unsigned int i; + + for (i = 0; i < STM32_MAX_EXTI_TRIGGER; i++) { + snprintf(name, sizeof(name), "exti%d", i); + + gpio = devm_gpiod_get_optional(&pdev->dev, name, GPIOD_IN); + if (IS_ERR_OR_NULL(gpio)) { + if (IS_ERR(gpio)) { + dev_err(&pdev->dev, "gpio %s get error %ld\n", + name, PTR_ERR(gpio)); + return PTR_ERR(gpio); + } + dev_dbg(&pdev->dev, "No %s gpio\n", name); + continue; + } + + irq = gpiod_to_irq(gpio); + if (irq < 0) { + dev_err(&pdev->dev, "gpio %d to irq failed\n", i); + return irq; + } + + ret = devm_request_irq(&pdev->dev, irq, + stm32_exti_trigger_handler, + 0, dev_name(&pdev->dev), pdev); + if (ret) { + dev_err(&pdev->dev, "request IRQ %d failed\n", irq); + return ret; + } + + /* + * gpios are configured as interrupts, so exti trigger path is + * configured in HW, and can now be used as external trigger + * source by other IPs. But getting interrupts when trigger + * occurs is unused here, so mask irq on exti controller by + * default. + */ + disable_irq(irq); + + trig = devm_iio_trigger_alloc(&pdev->dev, "%s", name); + if (!trig) + return -ENOMEM; + + trig->dev.parent = &pdev->dev; + trig->ops = &exti_trigger_ops; + + ret = devm_iio_trigger_register(&pdev->dev, trig); + if (ret) + return ret; + } + + return 0; +} + +static const struct of_device_id stm32_exti_trigger_of_match[] = { + { .compatible = "st,stm32-exti-trigger" }, + {}, +}; +MODULE_DEVICE_TABLE(of, stm32_exti_trigger_of_match); + +static struct platform_driver stm32_exti_trigger_driver = { + .probe = stm32_exti_trigger_probe, + .driver = { + .name = "stm32-exti-trigger", + .of_match_table = stm32_exti_trigger_of_match, + }, +}; +module_platform_driver(stm32_exti_trigger_driver); + +MODULE_AUTHOR("Fabrice Gasnier "); +MODULE_DESCRIPTION("STMicroelectronics STM32 EXTI-GPIO IIO trigger driver"); +MODULE_LICENSE("GPL v2"); +MODULE_ALIAS("platform:stm32-exti-trigger"); diff --git a/include/linux/iio/trigger/stm32-exti-trigger.h b/include/linux/iio/trigger/stm32-exti-trigger.h new file mode 100644 index 0000000..157ae58 --- /dev/null +++ b/include/linux/iio/trigger/stm32-exti-trigger.h @@ -0,0 +1,26 @@ +/* + * This file is part of STM32 EXTI Trigger driver + * + * Copyright (C) STMicroelectronics 2017 + * Author: Fabrice Gasnier . + * + * License terms: GNU General Public License (GPL), version 2 + */ + +#ifndef _STM32_EXTI_TRIGGER_H_ +#define _STM32_EXTI_TRIGGER_H_ + +#include + +#define STM32_EXTI(n) "exti"#n + +#if IS_ENABLED(CONFIG_IIO_STM32_EXTI_TRIGGER) +bool is_stm32_exti_trigger(struct iio_trigger *trig); +#else +static inline bool is_stm32_exti_trigger(struct iio_trigger *trig) +{ + return false; +} +#endif + +#endif