From patchwork Tue Dec 29 05:27:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xu Yilun X-Patchwork-Id: 354139 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=-11.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, 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 19B0BC433E0 for ; Tue, 29 Dec 2020 05:33:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CFC5F208BA for ; Tue, 29 Dec 2020 05:33:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725967AbgL2FdA (ORCPT ); Tue, 29 Dec 2020 00:33:00 -0500 Received: from mga18.intel.com ([134.134.136.126]:18331 "EHLO mga18.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725832AbgL2FdA (ORCPT ); Tue, 29 Dec 2020 00:33:00 -0500 IronPort-SDR: IFSDHHKH4D47i/s64fh9tv3Zh11KTUGQSYwyjdCJWBgKaIAPbwYFoM9GyE7kHkMiZSYeAgO3jy t0OmJV2qszlw== X-IronPort-AV: E=McAfee;i="6000,8403,9848"; a="164170711" X-IronPort-AV: E=Sophos;i="5.78,457,1599548400"; d="scan'208";a="164170711" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Dec 2020 21:32:19 -0800 IronPort-SDR: lacNd/9BuLT+r2v1mYTx6wdTVw3BvetJabXAOqHGiOBZGerSEbQsUMDhc+/jmfYp5V8Yw/I0g8 GpNrNsylZTGA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.78,457,1599548400"; d="scan'208";a="395307680" Received: from yilunxu-optiplex-7050.sh.intel.com ([10.239.159.141]) by fmsmga002.fm.intel.com with ESMTP; 28 Dec 2020 21:32:16 -0800 From: Xu Yilun To: broonie@kernel.org, linux-spi@vger.kernel.org Cc: trix@redhat.com, lgoncalv@redhat.com, yilun.xu@intel.com, hao.wu@intel.com, matthew.gerlach@linux.intel.com, russell.h.weight@intel.com, linux-kernel@vger.kernel.org Subject: [PATCH 0/2] fix the issue when xfer by spi-altera Date: Tue, 29 Dec 2020 13:27:40 +0800 Message-Id: <1609219662-27057-1-git-send-email-yilun.xu@intel.com> X-Mailer: git-send-email 2.7.4 Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org When doing spi xfer by spi-altera, divide by 0 exception happens in spi_transfer_wait(), This is because the xfer->speed_hz is always clamped to 0 by spi->controller->max_speed_hz, the feature is introduced in: commit 9326e4f1e5dd ("spi: Limit the spi device max speed to controller's max speed") The spi-altera doesn't have hardware indication for controller's max_speed_hz, so its value is uninitialized as 0. Patch #1 fixes the issue of spi_altera driver. When doing polling mode xfer, its transfer_one() callback should return 1, to indicate the xfer is finished. It should return 0 for irq mode xfer. With this patch the polling mode xfer is OK as it needs no spi_transfer_wait() anymore. But the irq mode xfer is still broken. So Patch #2 assumes 1khz xfer speed if the xfer->speed_hz is not assigned. I try to avoid the divide by 0 issue and ensures a reasonable tolerant waiting time in a generic way. Xu Yilun (2): spi: altera: fix return value for altera_spi_txrx() spi: fix the divide by 0 error when calculating xfer waiting time drivers/spi/spi-altera.c | 26 ++++++++++++++------------ drivers/spi/spi.c | 4 +++- 2 files changed, 17 insertions(+), 13 deletions(-)