Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp4868192yba; Wed, 10 Apr 2019 06:39:19 -0700 (PDT) X-Google-Smtp-Source: APXvYqzJj82mmQ7XXpUH8r1p142hwDOfiTMzTuV6lL69TeipvYH2OGDiIjwiPiclQx1zfQsy4EgY X-Received: by 2002:a63:c10d:: with SMTP id w13mr41143105pgf.311.1554903559486; Wed, 10 Apr 2019 06:39:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554903559; cv=none; d=google.com; s=arc-20160816; b=b3+pOff3vmfm1NLA6fxpyYTE8nbKR75hHMk0PwWL68di8gYdIrrYagqNsn/cpxuq3k p3c4I+qnXPWvBAnhR9eoAOkcTVwLOuInlyz0izoCGlk+y94FNDB5WTBOaHVudhtwzxo7 /TmuP5ZwK0osPr5gy2CJcSy6iaAHAjjUZQk6OIodOcZrl4JJHzQGONsOD3Sfw4S+yuRE iH6oAM10l/81CbbKCNdFzGue8JbxtwCgL9KFKjzc7Hb1NPqcf0fAawC3NRz/DSPno6S/ M5BQBLv6EFFXesFqNqpD4MMzQDAtcXTAm20krC1lb9MQCUYL8YoxDGNN77DmT1izWZ65 +1sg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:subject:cc :to:from; bh=Am2SwgGbkq5XgmV7DirhIOvgJz89Bpr24nHI/by220Q=; b=h2AfkLs6yZ5mzNGsS8snMF1HlgrjHtXmmpFHKj28+H/fd2wYZ9SxsAVHjq1nTLElM+ tOSRRQGJ1V2vNj5XYUUY1oX5mGaZZTaGZoVthQP0ryKTqEdvYAgay4BORbXdEM8df4iJ +Wx7G8yVZ1cDMJbAHP1KISuHEF7e11SxckrLGRV+BXaH9/jfwMZ0i0miRb/g/XFJIhtv Xa4Oe1QMiLFRnd+rIaQBvAKSq2afuDTqlOHRoClo+89CN78xafMEYjQYxzTmz2OnOCYD SlcTlbjAWem+MMM8+zEsilJP77CY7LGZkRW93GplIqMvAxDa9e8wguI7SrPHNMQYxL3f RF8w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a11si19077720pgw.384.2019.04.10.06.39.03; Wed, 10 Apr 2019 06:39:19 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732194AbfDJMyp (ORCPT + 99 others); Wed, 10 Apr 2019 08:54:45 -0400 Received: from smtp.asem.it ([151.1.184.197]:61682 "EHLO smtp.asem.it" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732186AbfDJMym (ORCPT ); Wed, 10 Apr 2019 08:54:42 -0400 Received: from webmail.asem.it by asem.it (smtp.asem.it) (SecurityGateway 5.5.0) with ESMTP id SG003804505.MSG for ; Wed, 10 Apr 2019 14:54:36 +0200S Received: from ASAS044.asem.intra (172.16.16.44) by ASAS044.asem.intra (172.16.16.44) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1261.35; Wed, 10 Apr 2019 14:54:35 +0200 Received: from flavio-x.asem.intra (172.16.17.208) by ASAS044.asem.intra (172.16.16.44) with Microsoft SMTP Server id 15.1.1261.35 via Frontend Transport; Wed, 10 Apr 2019 14:54:35 +0200 From: Flavio Suligoi To: Daniel Mack , Haojian Zhuang , Robert Jarzmik , Mark Brown CC: , , , Flavio Suligoi Subject: [PATCH 1/2] spi: pxa2xx: fix SCR (divisor) calculation Date: Wed, 10 Apr 2019 14:51:35 +0200 Message-ID: <1554900696-28858-1-git-send-email-f.suligoi@asem.it> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 Content-Type: text/plain X-SGHeloLookup-Result: pass smtp.helo=webmail.asem.it (ip=172.16.16.44) X-SGSPF-Result: none (smtp.asem.it) X-SGOP-RefID: str=0001.0A0B0201.5CADE78C.0048,ss=1,re=0.000,recu=0.000,reip=0.000,cl=1,cld=1,fgs=0 (_st=1 _vt=0 _iwf=0) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Calculate the divisor for the SCR (Serial Clock Rate), avoiding that the SSP transmission rate can be greater than the device rate. When the division between the SSP clock and the device rate generates a reminder, we have to increment by one the divisor. In this way the resulting SSP clock will never be greater than the device SPI max frequency. For example, with: - ssp_clk = 50 MHz - dev freq = 15 MHz without this patch the SSP clock will be greater than 15 MHz: - 25 MHz for PXA25x_SSP and CE4100_SSP - 16,56 MHz for the others Instead, with this patch, we have in both case an SSP clock of 12.5MHz, so the max rate of the SPI device clock is respected. Signed-off-by: Flavio Suligoi --- drivers/spi/spi-pxa2xx.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/drivers/spi/spi-pxa2xx.c b/drivers/spi/spi-pxa2xx.c index f7068cc..c9560a1 100644 --- a/drivers/spi/spi-pxa2xx.c +++ b/drivers/spi/spi-pxa2xx.c @@ -884,10 +884,15 @@ static unsigned int ssp_get_clk_div(struct driver_data *drv_data, int rate) rate = min_t(int, ssp_clk, rate); + /* + * Calculate the divisor for the SCR (Serial Clock Rate), avoiding + * that the SSP transmission rate can be greater than the device rate + */ if (ssp->type == PXA25x_SSP || ssp->type == CE4100_SSP) - return (ssp_clk / (2 * rate) - 1) & 0xff; + return (ssp_clk / (2 * rate) - 1 + + (ssp_clk % (2 * rate) ? 1 : 0)) & 0xff; else - return (ssp_clk / rate - 1) & 0xfff; + return (ssp_clk / rate - 1 + (ssp_clk % rate ? 1 : 0)) & 0xfff; } static unsigned int pxa2xx_ssp_get_clk_div(struct driver_data *drv_data, -- 2.7.4