From patchwork Tue Apr 27 08:54:49 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nuno Sa X-Patchwork-Id: 12225641 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D5FE0C433ED for ; Tue, 27 Apr 2021 08:52:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 67B4B6127A for ; Tue, 27 Apr 2021 08:52:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229629AbhD0IxY (ORCPT ); Tue, 27 Apr 2021 04:53:24 -0400 Received: from mx0a-00128a01.pphosted.com ([148.163.135.77]:37900 "EHLO mx0a-00128a01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229487AbhD0IxX (ORCPT ); Tue, 27 Apr 2021 04:53:23 -0400 Received: from pps.filterd (m0167088.ppops.net [127.0.0.1]) by mx0a-00128a01.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 13R8ok84005202; Tue, 27 Apr 2021 04:52:29 -0400 Received: from nwd2mta3.analog.com ([137.71.173.56]) by mx0a-00128a01.pphosted.com with ESMTP id 3866auh9d6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 27 Apr 2021 04:52:29 -0400 Received: from ASHBMBX8.ad.analog.com (ASHBMBX8.ad.analog.com [10.64.17.5]) by nwd2mta3.analog.com (8.14.7/8.14.7) with ESMTP id 13R8qSq6033985 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Tue, 27 Apr 2021 04:52:28 -0400 Received: from ASHBMBX8.ad.analog.com (10.64.17.5) by ASHBMBX8.ad.analog.com (10.64.17.5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.858.5; Tue, 27 Apr 2021 04:52:26 -0400 Received: from zeus.spd.analog.com (10.66.68.11) by ashbmbx8.ad.analog.com (10.64.17.5) with Microsoft SMTP Server id 15.2.858.5 via Frontend Transport; Tue, 27 Apr 2021 04:52:26 -0400 Received: from nsa.sphairon.box ([10.44.3.51]) by zeus.spd.analog.com (8.15.1/8.15.1) with ESMTP id 13R8qNJl007577; Tue, 27 Apr 2021 04:52:25 -0400 From: Nuno Sa To: CC: Jonathan Cameron , Michael Hennerich , Lars-Peter Clausen , Alexandru Ardelean Subject: [PATCH v3 1/6] iio: adis16475: do not return ints in irq handlers Date: Tue, 27 Apr 2021 10:54:49 +0200 Message-ID: <20210427085454.30616-2-nuno.sa@analog.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210427085454.30616-1-nuno.sa@analog.com> References: <20210427085454.30616-1-nuno.sa@analog.com> MIME-Version: 1.0 X-ADIRuleOP-NewSCL: Rule Triggered X-Proofpoint-ORIG-GUID: -WtUJpaE7J2xIebVYGPpQmwUiAhMzaGW X-Proofpoint-GUID: -WtUJpaE7J2xIebVYGPpQmwUiAhMzaGW X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391,18.0.761 definitions=2021-04-27_05:2021-04-27,2021-04-27 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxlogscore=999 priorityscore=1501 spamscore=0 bulkscore=0 impostorscore=0 clxscore=1015 mlxscore=0 lowpriorityscore=0 malwarescore=0 adultscore=0 phishscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104060000 definitions=main-2104270065 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org On an IRQ handler we should not return normal error codes as 'irqreturn_t' is expected. This is done by jumping to the 'check_burst32' label where we return 'IRQ_HANDLED'. Note that it is fine to do the burst32 check in this error path. If we have proper settings to apply burst32, we might just do the setup now so that the next sample already uses it. Fixes: fff7352bf7a3c ("iio: imu: Add support for adis16475") Reviewed-by: Alexandru Ardelean Signed-off-by: Nuno Sa --- drivers/iio/imu/adis16475.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/iio/imu/adis16475.c b/drivers/iio/imu/adis16475.c index 1de62fc79e0f..51b76444db0b 100644 --- a/drivers/iio/imu/adis16475.c +++ b/drivers/iio/imu/adis16475.c @@ -1068,7 +1068,7 @@ static irqreturn_t adis16475_trigger_handler(int irq, void *p) ret = spi_sync(adis->spi, &adis->msg); if (ret) - return ret; + goto check_burst32; adis->spi->max_speed_hz = cached_spi_speed_hz; buffer = adis->buffer; From patchwork Tue Apr 27 08:54:50 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nuno Sa X-Patchwork-Id: 12225643 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3239BC433B4 for ; Tue, 27 Apr 2021 08:52:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E6A6561002 for ; Tue, 27 Apr 2021 08:52:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234561AbhD0IxZ (ORCPT ); Tue, 27 Apr 2021 04:53:25 -0400 Received: from mx0a-00128a01.pphosted.com ([148.163.135.77]:38804 "EHLO mx0a-00128a01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229487AbhD0IxY (ORCPT ); Tue, 27 Apr 2021 04:53:24 -0400 Received: from pps.filterd (m0167089.ppops.net [127.0.0.1]) by mx0a-00128a01.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 13R8o3Xf021640; Tue, 27 Apr 2021 04:52:30 -0400 Received: from nwd2mta3.analog.com ([137.71.173.56]) by mx0a-00128a01.pphosted.com with ESMTP id 3865r9hbr2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 27 Apr 2021 04:52:30 -0400 Received: from ASHBMBX9.ad.analog.com (ASHBMBX9.ad.analog.com [10.64.17.10]) by nwd2mta3.analog.com (8.14.7/8.14.7) with ESMTP id 13R8qTYj033989 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Tue, 27 Apr 2021 04:52:29 -0400 Received: from ASHBMBX8.ad.analog.com (10.64.17.5) by ASHBMBX9.ad.analog.com (10.64.17.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.858.5; Tue, 27 Apr 2021 04:52:28 -0400 Received: from zeus.spd.analog.com (10.66.68.11) by ashbmbx8.ad.analog.com (10.64.17.5) with Microsoft SMTP Server id 15.2.858.5 via Frontend Transport; Tue, 27 Apr 2021 04:52:27 -0400 Received: from nsa.sphairon.box ([10.44.3.51]) by zeus.spd.analog.com (8.15.1/8.15.1) with ESMTP id 13R8qNJm007577; Tue, 27 Apr 2021 04:52:26 -0400 From: Nuno Sa To: CC: Jonathan Cameron , Michael Hennerich , Lars-Peter Clausen Subject: [PATCH v3 2/6] iio: adis_buffer: update device page after changing it Date: Tue, 27 Apr 2021 10:54:50 +0200 Message-ID: <20210427085454.30616-3-nuno.sa@analog.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210427085454.30616-1-nuno.sa@analog.com> References: <20210427085454.30616-1-nuno.sa@analog.com> MIME-Version: 1.0 X-ADIRuleOP-NewSCL: Rule Triggered X-Proofpoint-ORIG-GUID: tqogG-AMmGqhMgydF6P7j3nMhmCmb4HW X-Proofpoint-GUID: tqogG-AMmGqhMgydF6P7j3nMhmCmb4HW X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391,18.0.761 definitions=2021-04-27_05:2021-04-27,2021-04-27 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 clxscore=1015 mlxlogscore=731 priorityscore=1501 impostorscore=0 adultscore=0 suspectscore=0 lowpriorityscore=0 bulkscore=0 spamscore=0 malwarescore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104060000 definitions=main-2104270065 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org It makes more sense to update the device page as soon as we we successfully changed it. Moreover, a follow up patch will handle 'spi_sync' error path which would leave 'current_page' in a inconsistent state. Signed-off-by: Nuno Sa Reviewed-by: Alexandru Ardelean --- drivers/iio/imu/adis_buffer.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/iio/imu/adis_buffer.c b/drivers/iio/imu/adis_buffer.c index 0ae551a748eb..4fc0e0ca7561 100644 --- a/drivers/iio/imu/adis_buffer.c +++ b/drivers/iio/imu/adis_buffer.c @@ -140,6 +140,8 @@ static irqreturn_t adis_trigger_handler(int irq, void *p) mutex_unlock(&adis->state_lock); goto irq_done; } + + adis->current_page = 0; } } @@ -148,10 +150,8 @@ static irqreturn_t adis_trigger_handler(int irq, void *p) dev_err(&adis->spi->dev, "Failed to read data: %d", ret); - if (adis->data->has_paging) { - adis->current_page = 0; + if (adis->data->has_paging) mutex_unlock(&adis->state_lock); - } iio_push_to_buffers_with_timestamp(indio_dev, adis->buffer, pf->timestamp); From patchwork Tue Apr 27 08:54:51 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nuno Sa X-Patchwork-Id: 12225645 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 30EC1C433ED for ; Tue, 27 Apr 2021 08:52:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DD54B61002 for ; Tue, 27 Apr 2021 08:52:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235056AbhD0Ix1 (ORCPT ); Tue, 27 Apr 2021 04:53:27 -0400 Received: from mx0a-00128a01.pphosted.com ([148.163.135.77]:41184 "EHLO mx0a-00128a01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229487AbhD0Ix1 (ORCPT ); Tue, 27 Apr 2021 04:53:27 -0400 Received: from pps.filterd (m0167089.ppops.net [127.0.0.1]) by mx0a-00128a01.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 13R8o3Xg021640; Tue, 27 Apr 2021 04:52:32 -0400 Received: from nwd2mta3.analog.com ([137.71.173.56]) by mx0a-00128a01.pphosted.com with ESMTP id 3865r9hbr5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 27 Apr 2021 04:52:32 -0400 Received: from SCSQMBX11.ad.analog.com (SCSQMBX11.ad.analog.com [10.77.17.10]) by nwd2mta3.analog.com (8.14.7/8.14.7) with ESMTP id 13R8qT6Q033992 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Tue, 27 Apr 2021 04:52:31 -0400 Received: from SCSQMBX10.ad.analog.com (10.77.17.5) by SCSQMBX11.ad.analog.com (10.77.17.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.858.5; Tue, 27 Apr 2021 01:52:29 -0700 Received: from zeus.spd.analog.com (10.66.68.11) by scsqmbx10.ad.analog.com (10.77.17.5) with Microsoft SMTP Server id 15.2.858.5 via Frontend Transport; Tue, 27 Apr 2021 01:52:28 -0700 Received: from nsa.sphairon.box ([10.44.3.51]) by zeus.spd.analog.com (8.15.1/8.15.1) with ESMTP id 13R8qNJn007577; Tue, 27 Apr 2021 04:52:27 -0400 From: Nuno Sa To: CC: Jonathan Cameron , Michael Hennerich , Lars-Peter Clausen , Alexandru Ardelean Subject: [PATCH v3 3/6] iio: adis_buffer: don't push data to buffers on failure Date: Tue, 27 Apr 2021 10:54:51 +0200 Message-ID: <20210427085454.30616-4-nuno.sa@analog.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210427085454.30616-1-nuno.sa@analog.com> References: <20210427085454.30616-1-nuno.sa@analog.com> MIME-Version: 1.0 X-ADIRuleOP-NewSCL: Rule Triggered X-Proofpoint-ORIG-GUID: WwlXeV15xCtEH23CFjuMH5LRi0tAl7b1 X-Proofpoint-GUID: WwlXeV15xCtEH23CFjuMH5LRi0tAl7b1 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391,18.0.761 definitions=2021-04-27_05:2021-04-27,2021-04-27 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 clxscore=1015 mlxlogscore=999 priorityscore=1501 impostorscore=0 adultscore=0 suspectscore=0 lowpriorityscore=0 bulkscore=0 spamscore=0 malwarescore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104060000 definitions=main-2104270065 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org There's no point in pushing data to IIO buffers in case 'spi_sync()' fails. Reviewed-by: Alexandru Ardelean Signed-off-by: Nuno Sa --- drivers/iio/imu/adis_buffer.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/iio/imu/adis_buffer.c b/drivers/iio/imu/adis_buffer.c index 4fc0e0ca7561..f6dbfbd17d41 100644 --- a/drivers/iio/imu/adis_buffer.c +++ b/drivers/iio/imu/adis_buffer.c @@ -146,12 +146,12 @@ static irqreturn_t adis_trigger_handler(int irq, void *p) } ret = spi_sync(adis->spi, &adis->msg); - if (ret) - dev_err(&adis->spi->dev, "Failed to read data: %d", ret); - - if (adis->data->has_paging) mutex_unlock(&adis->state_lock); + if (ret) { + dev_err(&adis->spi->dev, "Failed to read data: %d", ret); + goto irq_done; + } iio_push_to_buffers_with_timestamp(indio_dev, adis->buffer, pf->timestamp); From patchwork Tue Apr 27 08:54:52 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nuno Sa X-Patchwork-Id: 12225647 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 19F9FC433B4 for ; Tue, 27 Apr 2021 08:52:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C242B611C1 for ; Tue, 27 Apr 2021 08:52:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235058AbhD0Ix3 (ORCPT ); Tue, 27 Apr 2021 04:53:29 -0400 Received: from mx0a-00128a01.pphosted.com ([148.163.135.77]:42626 "EHLO mx0a-00128a01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229487AbhD0Ix3 (ORCPT ); Tue, 27 Apr 2021 04:53:29 -0400 Received: from pps.filterd (m0167088.ppops.net [127.0.0.1]) by mx0a-00128a01.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 13R8osKA005256; Tue, 27 Apr 2021 04:52:34 -0400 Received: from nwd2mta3.analog.com ([137.71.173.56]) by mx0a-00128a01.pphosted.com with ESMTP id 3866auh9dj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 27 Apr 2021 04:52:34 -0400 Received: from ASHBMBX9.ad.analog.com (ASHBMBX9.ad.analog.com [10.64.17.10]) by nwd2mta3.analog.com (8.14.7/8.14.7) with ESMTP id 13R8qXBu034000 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Tue, 27 Apr 2021 04:52:33 -0400 Received: from ASHBCASHYB4.ad.analog.com (10.64.17.132) by ASHBMBX9.ad.analog.com (10.64.17.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.858.5; Tue, 27 Apr 2021 04:52:32 -0400 Received: from ASHBMBX8.ad.analog.com (10.64.17.5) by ASHBCASHYB4.ad.analog.com (10.64.17.132) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.858.5; Tue, 27 Apr 2021 04:52:31 -0400 Received: from zeus.spd.analog.com (10.66.68.11) by ashbmbx8.ad.analog.com (10.64.17.5) with Microsoft SMTP Server id 15.2.858.5 via Frontend Transport; Tue, 27 Apr 2021 04:52:31 -0400 Received: from nsa.sphairon.box ([10.44.3.51]) by zeus.spd.analog.com (8.15.1/8.15.1) with ESMTP id 13R8qNJo007577; Tue, 27 Apr 2021 04:52:28 -0400 From: Nuno Sa To: CC: Jonathan Cameron , Michael Hennerich , Lars-Peter Clausen , Alexandru Ardelean Subject: [PATCH v3 4/6] iio: adis: add burst_max_speed_hz variable Date: Tue, 27 Apr 2021 10:54:52 +0200 Message-ID: <20210427085454.30616-5-nuno.sa@analog.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210427085454.30616-1-nuno.sa@analog.com> References: <20210427085454.30616-1-nuno.sa@analog.com> MIME-Version: 1.0 X-ADIRuleOP-NewSCL: Rule Triggered X-Proofpoint-ORIG-GUID: CFpCoVPB1_FnJEqRj_cvhVrVwFOE8U1g X-Proofpoint-GUID: CFpCoVPB1_FnJEqRj_cvhVrVwFOE8U1g X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391,18.0.761 definitions=2021-04-27_05:2021-04-27,2021-04-27 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxlogscore=999 priorityscore=1501 spamscore=0 bulkscore=0 impostorscore=0 clxscore=1015 mlxscore=0 lowpriorityscore=0 malwarescore=0 adultscore=0 phishscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104060000 definitions=main-2104270065 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org Typically, in burst mode, the device cannot operate at it's full spi speed. Hence, the spi transfers for burst mode have to take this into account. With this change we avoid a potential race with the spi core as drivers were 'hacking' the device 'max_speed_hz' directly in the trigger handler. Reviewed-by: Alexandru Ardelean Signed-off-by: Nuno Sa --- drivers/iio/imu/adis_buffer.c | 4 ++++ include/linux/iio/imu/adis.h | 2 ++ 2 files changed, 6 insertions(+) diff --git a/drivers/iio/imu/adis_buffer.c b/drivers/iio/imu/adis_buffer.c index f6dbfbd17d41..351c303c8a8c 100644 --- a/drivers/iio/imu/adis_buffer.c +++ b/drivers/iio/imu/adis_buffer.c @@ -51,9 +51,13 @@ static int adis_update_scan_mode_burst(struct iio_dev *indio_dev, adis->xfer[0].tx_buf = tx; adis->xfer[0].bits_per_word = 8; adis->xfer[0].len = 2; + if (adis->data->burst_max_speed_hz) + adis->xfer[0].speed_hz = adis->data->burst_max_speed_hz; adis->xfer[1].rx_buf = adis->buffer; adis->xfer[1].bits_per_word = 8; adis->xfer[1].len = burst_length; + if (adis->data->burst_max_speed_hz) + adis->xfer[1].speed_hz = adis->data->burst_max_speed_hz; spi_message_init(&adis->msg); spi_message_add_tail(&adis->xfer[0], &adis->msg); diff --git a/include/linux/iio/imu/adis.h b/include/linux/iio/imu/adis.h index f9b728d490b1..cf49997d5903 100644 --- a/include/linux/iio/imu/adis.h +++ b/include/linux/iio/imu/adis.h @@ -55,6 +55,7 @@ struct adis_timeout { * this should be the minimum size supported by the device. * @burst_max_len: Holds the maximum burst size when the device supports * more than one burst mode with different sizes + * @burst_max_speed_hz: Maximum spi speed that can be used in burst mode */ struct adis_data { unsigned int read_delay; @@ -83,6 +84,7 @@ struct adis_data { unsigned int burst_reg_cmd; unsigned int burst_len; unsigned int burst_max_len; + unsigned int burst_max_speed_hz; }; /** From patchwork Tue Apr 27 08:54:53 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nuno Sa X-Patchwork-Id: 12225649 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DC284C43460 for ; Tue, 27 Apr 2021 08:52:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A676A6100B for ; Tue, 27 Apr 2021 08:52:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235062AbhD0Ixb (ORCPT ); Tue, 27 Apr 2021 04:53:31 -0400 Received: from mx0a-00128a01.pphosted.com ([148.163.135.77]:45464 "EHLO mx0a-00128a01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235070AbhD0Ixb (ORCPT ); Tue, 27 Apr 2021 04:53:31 -0400 Received: from pps.filterd (m0167088.ppops.net [127.0.0.1]) by mx0a-00128a01.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 13R8ok86005202; Tue, 27 Apr 2021 04:52:37 -0400 Received: from nwd2mta3.analog.com ([137.71.173.56]) by mx0a-00128a01.pphosted.com with ESMTP id 3866auh9dm-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 27 Apr 2021 04:52:37 -0400 Received: from SCSQMBX11.ad.analog.com (SCSQMBX11.ad.analog.com [10.77.17.10]) by nwd2mta3.analog.com (8.14.7/8.14.7) with ESMTP id 13R8qYPc034005 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Tue, 27 Apr 2021 04:52:36 -0400 Received: from SCSQCASHYB7.ad.analog.com (10.77.17.133) by SCSQMBX11.ad.analog.com (10.77.17.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.858.5; Tue, 27 Apr 2021 01:52:33 -0700 Received: from SCSQMBX10.ad.analog.com (10.77.17.5) by SCSQCASHYB7.ad.analog.com (10.77.17.133) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.858.5; Tue, 27 Apr 2021 01:52:33 -0700 Received: from zeus.spd.analog.com (10.66.68.11) by scsqmbx10.ad.analog.com (10.77.17.5) with Microsoft SMTP Server id 15.2.858.5 via Frontend Transport; Tue, 27 Apr 2021 01:52:32 -0700 Received: from nsa.sphairon.box ([10.44.3.51]) by zeus.spd.analog.com (8.15.1/8.15.1) with ESMTP id 13R8qNJp007577; Tue, 27 Apr 2021 04:52:29 -0400 From: Nuno Sa To: CC: Jonathan Cameron , Michael Hennerich , Lars-Peter Clausen , Alexandru Ardelean Subject: [PATCH v3 5/6] iio: adis16475: do not directly change spi 'max_speed_hz' Date: Tue, 27 Apr 2021 10:54:53 +0200 Message-ID: <20210427085454.30616-6-nuno.sa@analog.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210427085454.30616-1-nuno.sa@analog.com> References: <20210427085454.30616-1-nuno.sa@analog.com> MIME-Version: 1.0 X-ADIRuleOP-NewSCL: Rule Triggered X-Proofpoint-ORIG-GUID: Jyb71oQ8Gbx5zR8T3L8yHGE88jXJXda2 X-Proofpoint-GUID: Jyb71oQ8Gbx5zR8T3L8yHGE88jXJXda2 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391,18.0.761 definitions=2021-04-27_05:2021-04-27,2021-04-27 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxlogscore=999 priorityscore=1501 spamscore=0 bulkscore=0 impostorscore=0 clxscore=1015 mlxscore=0 lowpriorityscore=0 malwarescore=0 adultscore=0 phishscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104060000 definitions=main-2104270065 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org With commit 3ba10e37371d ("iio: adis: add burst_max_speed_hz variable"), we just need to define 'burst_max_speed_hz' and the adis core will take care of setting up the spi transfers for burst mode. Hence, we fix a potential race with the spi core where we could be left with an invalid 'max_speed_hz'. Reviewed-by: Alexandru Ardelean Fixes: fff7352bf7a3c ("iio: imu: Add support for adis16475") Signed-off-by: Nuno Sa --- drivers/iio/imu/adis16475.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/drivers/iio/imu/adis16475.c b/drivers/iio/imu/adis16475.c index 51b76444db0b..5654c0c15426 100644 --- a/drivers/iio/imu/adis16475.c +++ b/drivers/iio/imu/adis16475.c @@ -645,7 +645,8 @@ static int adis16475_enable_irq(struct adis *adis, bool enable) .timeouts = (_timeouts), \ .burst_reg_cmd = ADIS16475_REG_GLOB_CMD, \ .burst_len = ADIS16475_BURST_MAX_DATA, \ - .burst_max_len = ADIS16475_BURST32_MAX_DATA \ + .burst_max_len = ADIS16475_BURST32_MAX_DATA, \ + .burst_max_speed_hz = ADIS16475_BURST_MAX_SPEED \ } static const struct adis16475_sync adis16475_sync_mode[] = { @@ -1062,15 +1063,11 @@ static irqreturn_t adis16475_trigger_handler(int irq, void *p) bool valid; /* offset until the first element after gyro and accel */ const u8 offset = st->burst32 ? 13 : 7; - const u32 cached_spi_speed_hz = adis->spi->max_speed_hz; - - adis->spi->max_speed_hz = ADIS16475_BURST_MAX_SPEED; ret = spi_sync(adis->spi, &adis->msg); if (ret) goto check_burst32; - adis->spi->max_speed_hz = cached_spi_speed_hz; buffer = adis->buffer; crc = be16_to_cpu(buffer[offset + 2]); From patchwork Tue Apr 27 08:54:54 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nuno Sa X-Patchwork-Id: 12225651 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8EFF0C433ED for ; Tue, 27 Apr 2021 08:52:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5F215610C9 for ; Tue, 27 Apr 2021 08:52:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235070AbhD0Ixc (ORCPT ); Tue, 27 Apr 2021 04:53:32 -0400 Received: from mx0a-00128a01.pphosted.com ([148.163.135.77]:47068 "EHLO mx0a-00128a01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229487AbhD0Ixc (ORCPT ); Tue, 27 Apr 2021 04:53:32 -0400 Received: from pps.filterd (m0167089.ppops.net [127.0.0.1]) by mx0a-00128a01.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 13R8o3cF021646; Tue, 27 Apr 2021 04:52:37 -0400 Received: from nwd2mta4.analog.com ([137.71.173.58]) by mx0a-00128a01.pphosted.com with ESMTP id 3865r9hbrb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 27 Apr 2021 04:52:37 -0400 Received: from ASHBMBX8.ad.analog.com (ASHBMBX8.ad.analog.com [10.64.17.5]) by nwd2mta4.analog.com (8.14.7/8.14.7) with ESMTP id 13R8qaog036602 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Tue, 27 Apr 2021 04:52:36 -0400 Received: from ASHBCASHYB4.ad.analog.com (10.64.17.132) by ASHBMBX8.ad.analog.com (10.64.17.5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.858.5; Tue, 27 Apr 2021 04:52:34 -0400 Received: from ASHBMBX8.ad.analog.com (10.64.17.5) by ASHBCASHYB4.ad.analog.com (10.64.17.132) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.858.5; Tue, 27 Apr 2021 04:52:34 -0400 Received: from zeus.spd.analog.com (10.66.68.11) by ashbmbx8.ad.analog.com (10.64.17.5) with Microsoft SMTP Server id 15.2.858.5 via Frontend Transport; Tue, 27 Apr 2021 04:52:34 -0400 Received: from nsa.sphairon.box ([10.44.3.51]) by zeus.spd.analog.com (8.15.1/8.15.1) with ESMTP id 13R8qNJq007577; Tue, 27 Apr 2021 04:52:30 -0400 From: Nuno Sa To: CC: Jonathan Cameron , Michael Hennerich , Lars-Peter Clausen , Alexandru Ardelean Subject: [PATCH v3 6/6] iio: adis16400: do not directly change spi 'max_speed_hz' Date: Tue, 27 Apr 2021 10:54:54 +0200 Message-ID: <20210427085454.30616-7-nuno.sa@analog.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210427085454.30616-1-nuno.sa@analog.com> References: <20210427085454.30616-1-nuno.sa@analog.com> MIME-Version: 1.0 X-ADIRuleOP-NewSCL: Rule Triggered X-Proofpoint-ORIG-GUID: tTqj30ESYXKdU-XmcmZVZapkHSJ2DskB X-Proofpoint-GUID: tTqj30ESYXKdU-XmcmZVZapkHSJ2DskB X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391,18.0.761 definitions=2021-04-27_05:2021-04-27,2021-04-27 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 clxscore=1015 mlxlogscore=999 priorityscore=1501 impostorscore=0 adultscore=0 suspectscore=0 lowpriorityscore=0 bulkscore=0 spamscore=0 malwarescore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104060000 definitions=main-2104270065 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org With commit 3ba10e37371d ("iio: adis: add burst_max_speed_hz variable"), we just need to define 'burst_max_speed_hz' and the adis core will take care of setting up the spi transfers for burst mode. Hence, we fix a potential race with the spi core where we could be left witn an invalid 'max_speed_hz'. Reviewed-by: Alexandru Ardelean Fixes: 5eda3550a3cc1 ("staging:iio:adis16400: Preallocate transfer message") Signed-off-by: Nuno Sa --- drivers/iio/imu/adis16400.c | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/drivers/iio/imu/adis16400.c b/drivers/iio/imu/adis16400.c index b2f92b55b910..cb8d3ffab6fc 100644 --- a/drivers/iio/imu/adis16400.c +++ b/drivers/iio/imu/adis16400.c @@ -641,25 +641,13 @@ static irqreturn_t adis16400_trigger_handler(int irq, void *p) struct iio_dev *indio_dev = pf->indio_dev; struct adis16400_state *st = iio_priv(indio_dev); struct adis *adis = &st->adis; - u32 old_speed_hz = st->adis.spi->max_speed_hz; void *buffer; int ret; - if (!(st->variant->flags & ADIS16400_NO_BURST) && - st->adis.spi->max_speed_hz > ADIS16400_SPI_BURST) { - st->adis.spi->max_speed_hz = ADIS16400_SPI_BURST; - spi_setup(st->adis.spi); - } - ret = spi_sync(adis->spi, &adis->msg); if (ret) dev_err(&adis->spi->dev, "Failed to read data: %d\n", ret); - if (!(st->variant->flags & ADIS16400_NO_BURST)) { - st->adis.spi->max_speed_hz = old_speed_hz; - spi_setup(st->adis.spi); - } - if (st->variant->flags & ADIS16400_BURST_DIAG_STAT) buffer = adis->buffer + sizeof(u16); else @@ -965,7 +953,8 @@ static const char * const adis16400_status_error_msgs[] = { BIT(ADIS16400_DIAG_STAT_POWER_LOW), \ .timeouts = (_timeouts), \ .burst_reg_cmd = ADIS16400_GLOB_CMD, \ - .burst_len = (_burst_len) \ + .burst_len = (_burst_len), \ + .burst_max_speed_hz = ADIS16400_SPI_BURST \ } static const struct adis_timeout adis16300_timeouts = {