From patchwork Thu Sep 1 20:38:40 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Kaiser X-Patchwork-Id: 9309821 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 2B5CB607D6 for ; Thu, 1 Sep 2016 21:54:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5FDB228425 for ; Thu, 1 Sep 2016 21:54:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 545912955B; Thu, 1 Sep 2016 21:54:16 +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=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=unavailable 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 0480228425 for ; Thu, 1 Sep 2016 21:54:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754360AbcIAVx7 (ORCPT ); Thu, 1 Sep 2016 17:53:59 -0400 Received: from viti.kaiser.cx ([85.214.81.225]:43213 "EHLO viti.kaiser.cx" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754292AbcIAVxa (ORCPT ); Thu, 1 Sep 2016 17:53:30 -0400 X-Greylist: delayed 1800 seconds by postgrey-1.27 at vger.kernel.org; Thu, 01 Sep 2016 17:53:30 EDT Received: from p4fd7885c.dip0.t-ipconnect.de ([79.215.136.92] helo=reykholt.kaiser.cx) by viti.kaiser.cx with esmtpsa (TLS1.2:DHE_RSA_AES_128_CBC_SHA1:128) (Exim 4.80) (envelope-from ) id 1bfYl1-0004lA-Te; Thu, 01 Sep 2016 22:38:44 +0200 Received: from martin by reykholt.kaiser.cx with local (Exim 4.80) (envelope-from ) id 1bfYky-00024n-KV; Thu, 01 Sep 2016 22:38:40 +0200 Date: Thu, 1 Sep 2016 22:38:40 +0200 From: Martin Kaiser To: Mark Brown Cc: linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/2] spi: imx: set spi_bus_clk for mx1, mx31 and mx35 Message-ID: <20160901203840.GA7972@reykholt.kaiser.cx> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-spi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Modify spi_imx_clkdiv_2() to return the resulting bus clock frequency when the selected clock divider is applied. Set spi_imx->spi_bus_clk to this frequency. If spi_bus_clk is unset, spi_imx_calculate_timeout() causes a division by 0. [ 90.356106] Division by zero in kernel. [ 90.362631] CPU: 0 PID: 130 Comm: spidev_test Not tainted 4.8.0-rc3-next-20160825+ #105 [ 90.372461] Hardware name: Freescale i.MX25 (Device Tree Support) [ 90.378708] Backtrace: [...] [ 90.409251] [] (__div0) from [] (Ldiv0+0x8/0x10) [ 90.415783] [] (spi_imx_calculate_timeout [spi_imx]) from [] (spi_imx_transfer+0x220/0x278 [spi_imx]) [ 90.426924] [] (spi_imx_transfer [spi_imx]) from [] (spi_bitbang_transfer_one+0x60/0x8c) [ 90.436864] r8:d3ad52c8 r7:d3ad5800 r6:d3ad5000 r5:d3ae4f40 r4:00000000 [ 90.443737] [] (spi_bitbang_transfer_one) from [] (spi_transfer_one_message+0x12c/0x37c) [ 90.453668] r8:c0a530e4 r7:d3ad5178 r6:d3ad5800 r5:d3ad5000 r4:d3b13e88 r3:00000000 [ 90.461633] [] (spi_transfer_one_message) from [] (__spi_pump_messages+0x528/0x568) Signed-off-by: Martin Kaiser --- drivers/spi/spi-imx.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/drivers/spi/spi-imx.c b/drivers/spi/spi-imx.c index f63cb30..5cc72be 100644 --- a/drivers/spi/spi-imx.c +++ b/drivers/spi/spi-imx.c @@ -186,17 +186,19 @@ static unsigned int spi_imx_clkdiv_1(unsigned int fin, /* MX1, MX31, MX35, MX51 CSPI */ static unsigned int spi_imx_clkdiv_2(unsigned int fin, - unsigned int fspi) + unsigned int fspi, unsigned int *fres) { int i, div = 4; for (i = 0; i < 7; i++) { if (fspi * div >= fin) - return i; + goto out; div <<= 1; } - return 7; +out: + *fres = fin / div; + return i; } static int spi_imx_bytes_per_word(const int bpw) @@ -482,9 +484,11 @@ static int mx31_config(struct spi_device *spi, struct spi_imx_config *config) { struct spi_imx_data *spi_imx = spi_master_get_devdata(spi->master); unsigned int reg = MX31_CSPICTRL_ENABLE | MX31_CSPICTRL_MASTER; + unsigned int clk; - reg |= spi_imx_clkdiv_2(spi_imx->spi_clk, config->speed_hz) << + reg |= spi_imx_clkdiv_2(spi_imx->spi_clk, config->speed_hz, &clk) << MX31_CSPICTRL_DR_SHIFT; + spi_imx->spi_bus_clk = clk; if (is_imx35_cspi(spi_imx)) { reg |= (config->bpw - 1) << MX35_CSPICTRL_BL_SHIFT; @@ -625,9 +629,12 @@ static int mx1_config(struct spi_device *spi, struct spi_imx_config *config) { struct spi_imx_data *spi_imx = spi_master_get_devdata(spi->master); unsigned int reg = MX1_CSPICTRL_ENABLE | MX1_CSPICTRL_MASTER; + unsigned int clk; - reg |= spi_imx_clkdiv_2(spi_imx->spi_clk, config->speed_hz) << + reg |= spi_imx_clkdiv_2(spi_imx->spi_clk, config->speed_hz, &clk) << MX1_CSPICTRL_DR_SHIFT; + spi_imx->spi_bus_clk = clk; + reg |= config->bpw - 1; if (spi->mode & SPI_CPHA)