From patchwork Thu Oct 25 22:32:26 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denis CIOCCA X-Patchwork-Id: 10656767 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 414A513A4 for ; Thu, 25 Oct 2018 22:33:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 26A252C60E for ; Thu, 25 Oct 2018 22:33:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 17A442C61A; Thu, 25 Oct 2018 22:33:58 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham 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 5BBF92C60E for ; Thu, 25 Oct 2018 22:33:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726448AbeJZHI0 (ORCPT ); Fri, 26 Oct 2018 03:08:26 -0400 Received: from mx07-00178001.pphosted.com ([62.209.51.94]:6318 "EHLO mx07-00178001.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726246AbeJZHIZ (ORCPT ); Fri, 26 Oct 2018 03:08:25 -0400 Received: from pps.filterd (m0046037.ppops.net [127.0.0.1]) by mx07-.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id w9PMT17g019936; Fri, 26 Oct 2018 00:33:29 +0200 Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-00178001.pphosted.com with ESMTP id 2n7t4tpc8v-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Fri, 26 Oct 2018 00:33:29 +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 4BB2634; Thu, 25 Oct 2018 22:33:28 +0000 (GMT) Received: from Webmail-eu.st.com (sfhdag2node1.st.com [10.75.127.4]) by zeta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 217A2FA7; Thu, 25 Oct 2018 22:33:28 +0000 (GMT) Received: from localhost (10.75.127.44) by SFHDAG2NODE1.st.com (10.75.127.4) with Microsoft SMTP Server (TLS) id 15.0.1347.2; Fri, 26 Oct 2018 00:33:27 +0200 From: Denis Ciocca To: , , , , , , CC: Denis Ciocca Subject: [PATCH] iio:st_magn: enable trigger before enabling sensor Date: Thu, 25 Oct 2018 15:32:26 -0700 Message-ID: <20181025223226.10292-1-denis.ciocca@st.com> X-Mailer: git-send-email 2.19.1 MIME-Version: 1.0 X-Originating-IP: [10.75.127.44] X-ClientProxiedBy: SFHDAG4NODE2.st.com (10.75.127.11) To SFHDAG2NODE1.st.com (10.75.127.4) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2018-10-25_12:,, signatures=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 From logical point of view driver should be ready to receive irqs before enabling the sensor itself. This patch is fixing also an issue related to sensors that generate interrupts unconditionally, (DRDY pads) when interrupt level is used. Signed-off-by: Martin Kelly Signed-off-by: Denis Ciocca --- drivers/iio/magnetometer/st_magn_buffer.c | 33 +++++++++++------------ 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/drivers/iio/magnetometer/st_magn_buffer.c b/drivers/iio/magnetometer/st_magn_buffer.c index 0a9e8fadfa9d..097e6e88a464 100644 --- a/drivers/iio/magnetometer/st_magn_buffer.c +++ b/drivers/iio/magnetometer/st_magn_buffer.c @@ -30,11 +30,6 @@ int st_magn_trig_set_state(struct iio_trigger *trig, bool state) return st_sensors_set_dataready_irq(indio_dev, state); } -static int st_magn_buffer_preenable(struct iio_dev *indio_dev) -{ - return st_sensors_set_enable(indio_dev, true); -} - static int st_magn_buffer_postenable(struct iio_dev *indio_dev) { int err; @@ -42,40 +37,44 @@ static int st_magn_buffer_postenable(struct iio_dev *indio_dev) mdata->buffer_data = kmalloc(indio_dev->scan_bytes, GFP_KERNEL); if (mdata->buffer_data == NULL) { - err = -ENOMEM; - goto allocate_memory_error; + return -ENOMEM; } err = iio_triggered_buffer_postenable(indio_dev); if (err < 0) - goto st_magn_buffer_postenable_error; + goto st_magn_buffer_free_buffer_data; + + err = st_sensors_set_enable(indio_dev, true); + if (err < 0) + goto st_magn_buffer_buffer_predisable; return err; -st_magn_buffer_postenable_error: +st_magn_buffer_buffer_predisable: + iio_triggered_buffer_predisable(indio_dev); +st_magn_buffer_free_buffer_data: kfree(mdata->buffer_data); -allocate_memory_error: return err; } static int st_magn_buffer_predisable(struct iio_dev *indio_dev) { - int err; + int err = 0, err2; struct st_sensor_data *mdata = iio_priv(indio_dev); - err = iio_triggered_buffer_predisable(indio_dev); - if (err < 0) - goto st_magn_buffer_predisable_error; + err2 = st_sensors_set_enable(indio_dev, false); + if (err2 < 0) + err = err2; - err = st_sensors_set_enable(indio_dev, false); + err2 = iio_triggered_buffer_predisable(indio_dev); + if (err2 < 0) + err = err2; -st_magn_buffer_predisable_error: kfree(mdata->buffer_data); return err; } static const struct iio_buffer_setup_ops st_magn_buffer_setup_ops = { - .preenable = &st_magn_buffer_preenable, .postenable = &st_magn_buffer_postenable, .predisable = &st_magn_buffer_predisable, };