Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp5738902yba; Thu, 11 Apr 2019 04:56:57 -0700 (PDT) X-Google-Smtp-Source: APXvYqw07xAjPRfT3SxwDWHzGh2l3cD0rAJyK8QViz1O6c4p86F97uL95ez/2t0ma0U4llfr69u9 X-Received: by 2002:a17:902:a513:: with SMTP id s19mr48209410plq.97.1554983817216; Thu, 11 Apr 2019 04:56:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554983817; cv=none; d=google.com; s=arc-20160816; b=uaPqYjHV+hcUfs1AuNiwVjdlujFkTNBoQOZ0ENg9wBoLH8zloxndPWiXsmVv60R4CF S5xyKsOPsro0t8BvlrJuEcWCNVFo4YnJof+3B9kgJSQV+0WceF8ejZw9YbkU08i3U/+u bjLLvUdbAj3nR4nfVVzBPlV0esYmBtJd9gwRXYJX38kN0ijUQybzVIFfxsycr/vk/chU xwqP8vNpQnPhdLPV/NPqR7t5pR6Sax30OX3OlWwMmE1HHSXt2WNbIP4FDCRGHgU/+H6A ojNChbewc+wBPA1mnMUUVDfr/OvpioCWysQkgwOz3/OkUdC42LwSqD9/Oc+0o6yIlR4W 3i4w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=6lRNhQPQnuKOOovIuh6mX+Ue7avULMl1k3KRkaITjYs=; b=uRzxcouohjEh8rK3fqk/yjGqwKe0qSHehZmZTq0igRvTZFEH2MCy572XMiY+Yl+Hhd Cf4R8KwGkPjvFJiqmRPnUOaELyQ5n2wKu4RH0oSeLuqfti1f/MVaMb9/QCppaI33UVFq nwoejt4OcyQyK64/tcaGl99QGceGBZJZ3bkCRP8f7nChFi3UFoIoNbL5vKAxuqQCL1n7 T02V+mC+ySKFYdN6qWZdCKYdO9otK7vKWn0qkGZ2NNRMRjYAVXhcYIDKs6N4Q4u+MBE3 RMfS2oxWu+8jG6gteVgkkAS4j0QGjs0iGIus6EX5i/QDJZxXNuYg6JtE6ErjVkqu1dtf 6LbQ== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e9si32197059pgn.236.2019.04.11.04.56.41; Thu, 11 Apr 2019 04:56:57 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726635AbfDKL4H (ORCPT + 99 others); Thu, 11 Apr 2019 07:56:07 -0400 Received: from mga04.intel.com ([192.55.52.120]:58491 "EHLO mga04.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726494AbfDKL4H (ORCPT ); Thu, 11 Apr 2019 07:56:07 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 11 Apr 2019 04:56:06 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.60,337,1549958400"; d="scan'208";a="134858982" Received: from unknown (HELO [10.237.72.155]) ([10.237.72.155]) by orsmga006.jf.intel.com with ESMTP; 11 Apr 2019 04:56:02 -0700 Subject: Re: [PATCH 1/2] spi: pxa2xx: fix SCR (divisor) calculation To: Flavio Suligoi , Daniel Mack , Haojian Zhuang , Robert Jarzmik , Mark Brown Cc: linux-arm-kernel@lists.infradead.org, linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org References: <1554900696-28858-1-git-send-email-f.suligoi@asem.it> From: Jarkko Nikula Message-ID: <34b8442a-15ac-dea2-a088-fde8b1966e1e@linux.intel.com> Date: Thu, 11 Apr 2019 14:55:53 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 MIME-Version: 1.0 In-Reply-To: <1554900696-28858-1-git-send-email-f.suligoi@asem.it> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 4/10/19 3:51 PM, Flavio Suligoi wrote: > 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; > } > I think DIV_ROUND_UP() - 1 would also fix this? I realized we have also another issue here with the low rates. Calculated divider will underflow due masking with 0xff or 0xfff when the rate is low enough. Would you want to fix that by setting the ctlr->min_speed_hz so that spi core can validate the rate? I'm asking since it goes well together with your fix. Maybe one patch setting the min_speed_hz and getting masking off from here and then another fixing the rate calculation. -- Jarkko