From patchwork Tue Oct 25 16:25:16 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fabrice Gasnier X-Patchwork-Id: 9395003 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 22A046077F for ; Tue, 25 Oct 2016 16:28:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 14E2B2953D for ; Tue, 25 Oct 2016 16:28:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0981D295AB; Tue, 25 Oct 2016 16:28:31 +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=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 6989D2953E for ; Tue, 25 Oct 2016 16:28:28 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1bz4Z7-0002iQ-DV; Tue, 25 Oct 2016 16:27:05 +0000 Received: from mx08-00178001.pphosted.com ([91.207.212.93] helo=mx07-00178001.pphosted.com) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1bz4YX-0002Hn-71 for linux-arm-kernel@lists.infradead.org; Tue, 25 Oct 2016 16:26:33 +0000 Received: from pps.filterd (m0046660.ppops.net [127.0.0.1]) by mx08-00178001.pphosted.com (8.16.0.11/8.16.0.11) with SMTP id u9PGB3kK019779; Tue, 25 Oct 2016 18:25:52 +0200 Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx08-.pphosted.com with ESMTP id 267w85p2ug-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Tue, 25 Oct 2016 18:25:52 +0200 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 BE16E31; Tue, 25 Oct 2016 16:25:51 +0000 (GMT) Received: from Webmail-eu.st.com (Safex1hubcas22.st.com [10.75.90.92]) by zeta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 91C1B2A6C; Tue, 25 Oct 2016 16:25:51 +0000 (GMT) Received: from localhost (10.48.0.167) by Webmail-ga.st.com (10.75.90.48) with Microsoft SMTP Server (TLS) id 14.3.294.0; Tue, 25 Oct 2016 18:25:51 +0200 From: Fabrice Gasnier To: , , , Subject: [PATCH 04/10] iio: adc: stm32: add optional support for exti gpios Date: Tue, 25 Oct 2016 18:25:16 +0200 Message-ID: <1477412722-24061-5-git-send-email-fabrice.gasnier@st.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1477412722-24061-1-git-send-email-fabrice.gasnier@st.com> References: <1477412722-24061-1-git-send-email-fabrice.gasnier@st.com> MIME-Version: 1.0 X-Originating-IP: [10.48.0.167] X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2016-10-25_15:, , signatures=0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20161025_092629_907826_34022720 X-CRM114-Status: GOOD ( 17.09 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mark.rutland@arm.com, lars@metafoo.de, alexandre.torgue@st.com, pmeerw@pmeerw.net, linux@armlinux.org.uk, robh+dt@kernel.org, mcoquelin.stm32@gmail.com, knaack.h@gmx.de, fabrice.gasnier@st.com, jic23@kernel.org 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 STM32 ADC may use EXTi signals routed internally as trigger source for conversions. Configure them as interrupt to configure this path in HW to adc. 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/adc/stm32/stm32-adc.c | 45 +++++++++++++++++++++++++++++++++++++++ drivers/iio/adc/stm32/stm32-adc.h | 3 +++ 2 files changed, 48 insertions(+) diff --git a/drivers/iio/adc/stm32/stm32-adc.c b/drivers/iio/adc/stm32/stm32-adc.c index 25d0307..1a13450 100644 --- a/drivers/iio/adc/stm32/stm32-adc.c +++ b/drivers/iio/adc/stm32/stm32-adc.c @@ -482,6 +482,12 @@ static irqreturn_t stm32_adc_common_isr(int irq, void *data) return ret; } +static irqreturn_t stm32_adc_exti_handler(int irq, void *data) +{ + /* Exti handler should not be invoqued, and is not used */ + return IRQ_HANDLED; +} + /** * stm32_adc_validate_trigger() - validate trigger for stm32 adc * @indio_dev: IIO device @@ -1051,6 +1057,41 @@ static void stm32_adc_unregister(struct stm32_adc *adc) } } +static int stm32_adc_exti_probe(struct stm32_adc_common *common) +{ + int i, irq, ret; + + common->gpios = devm_gpiod_get_array_optional(common->dev, NULL, + GPIOD_IN); + if (!common->gpios) + return 0; + + for (i = 0; i < common->gpios->ndescs; i++) { + irq = gpiod_to_irq(common->gpios->desc[i]); + if (irq < 0) { + dev_err(common->dev, "gpio %d to irq failed\n", i); + return irq; + } + + ret = devm_request_irq(common->dev, irq, stm32_adc_exti_handler, + 0, dev_name(common->dev), common); + if (ret) { + dev_err(common->dev, "request IRQ %d failed\n", irq); + return ret; + } + + /* + * gpios are configured as interrupts, so exti trigger path is + * configured in HW. But getting interrupts when starting + * conversions is unused here, so mask it in on exti + * controller by default. + */ + disable_irq(irq); + } + + return 0; +} + int stm32_adc_probe(struct platform_device *pdev) { struct device_node *np = pdev->dev.of_node, *child; @@ -1131,6 +1172,10 @@ int stm32_adc_probe(struct platform_device *pdev) goto err_clk_disable; } + ret = stm32_adc_exti_probe(common); + if (ret) + goto err_clk_disable; + /* Parse adc child nodes to retrieve master/slave instances data */ for_each_available_child_of_node(np, child) { ret = stm32_adc_register(common, child); diff --git a/drivers/iio/adc/stm32/stm32-adc.h b/drivers/iio/adc/stm32/stm32-adc.h index 01a0dda..fe3568b 100644 --- a/drivers/iio/adc/stm32/stm32-adc.h +++ b/drivers/iio/adc/stm32/stm32-adc.h @@ -23,6 +23,7 @@ #define __STM32_ADC_H #include +#include #include /* @@ -323,6 +324,7 @@ struct stm32_adc { * @aclk: common clock for the analog circuitry * @vref: regulator reference * @vref_mv: vref voltage (mv) + * @gpio_descs: gpio descriptor used to configure EXTi triggers * @lock: mutex */ struct stm32_adc_common { @@ -335,6 +337,7 @@ struct stm32_adc_common { struct clk *aclk; struct regulator *vref; int vref_mv; + struct gpio_descs *gpios; struct mutex lock; /* read_raw lock */ };