From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932088AbdA3OEz (ORCPT ); Mon, 30 Jan 2017 09:04:55 -0500 Received: from mx08-00178001.pphosted.com ([91.207.212.93]:37375 "EHLO mx07-00178001.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753374AbdA3OEj (ORCPT ); Mon, 30 Jan 2017 09:04:39 -0500 From: Fabrice Gasnier To: , , , , , CC: , , , , , , , , , Subject: [PATCH 4/5] iio: trigger: add support for STM32 EXTI triggers Date: Mon, 30 Jan 2017 14:57:42 +0100 Message-ID: <1485784663-19505-5-git-send-email-fabrice.gasnier@st.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1485784663-19505-1-git-send-email-fabrice.gasnier@st.com> References: <1485784663-19505-1-git-send-email-fabrice.gasnier@st.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.75.127.51] X-ClientProxiedBy: SFHDAG6NODE3.st.com (10.75.127.18) 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 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 | 10 ++ 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, 161 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..b0c5104 100644 --- a/drivers/iio/trigger/Kconfig +++ b/drivers/iio/trigger/Kconfig @@ -24,6 +24,16 @@ 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 && MFD_STM32_TIMERS) || COMPILE_TEST + 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 -- 1.9.1