Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp381738yba; Fri, 12 Apr 2019 05:37:43 -0700 (PDT) X-Google-Smtp-Source: APXvYqxiVn/OMGMgAjLkcHWOcUI38X65iZ2uXa21PskaRuRQhzhl/J5PRourY1EsOpJGl8U31UPE X-Received: by 2002:a63:9dc4:: with SMTP id i187mr49820001pgd.259.1555072663126; Fri, 12 Apr 2019 05:37:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555072663; cv=none; d=google.com; s=arc-20160816; b=JKm7b1kd1IbkxtQIndmYx8vNkQa7X3i8XJXrQPR/tczidjIqmMqY+6nrFFWrpzfwLg h0jPq66JUNL1KVyAQc695ZEYPNp9fcI8dvhMRR1uZq8KgjbYTwckrvyd+0Kli3OL62rO mOKSkH3fEOXW6cTNJ1y2KezJAtAf1sP0G7v5SjYloYBiwU4gOvnTFW0GIc5Hi7BrFOA+ qBhH5Juk0vBd47bkI8MxaDypbM6N07G+4XNShxVm78iMhky3W1Q3okxtO58r7XuVm/Hx /pXXkKx+fHDL+PCPL9C09SUM8/RNIFbImpS2V08qtxVVFLNHhGq0LA0+jEIHzKpdb+y9 nnlw== 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=9+oIh2/S+XUD0W9AcUiog4kpLeb5bXJG1v21nriMy6o=; b=pZ/FIJ5bct6rk7YeSqUnwPn/aMTkqvzZ8GDtyKNMarlrvVHtHDA1F+Pv4o16Q7ml3w G3Sp4DfSqGcyFAq3EBC6xsA08gJbIza02jfC7GPj1a+5I8r+q03Mnj5ARRnmn7Utxvls Id5JztrMSWc8dKjIgqF7hojp/w6wzhyV6Yndg8Z5T/OCiY0H8iiIJnKwDVdu2kwVwXsq s8Y3+toZ5e4VAXq2zwncJ2Rh3oJIGDvdMu8VqFKQhWUh+GQ8KTpFRIQYsdO65vN2Kw9B uMZ7j30Izhc9nZYx6m8ggwgQDaFoTo0pkbqq149ute3uzLO0rF/cnuym/LvGX4PcAb5l 9eTg== 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 r190si41377315pfc.14.2019.04.12.05.36.57; Fri, 12 Apr 2019 05:37:43 -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 S1727122AbfDLMgD (ORCPT + 99 others); Fri, 12 Apr 2019 08:36:03 -0400 Received: from mga17.intel.com ([192.55.52.151]:10796 "EHLO mga17.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726714AbfDLMgD (ORCPT ); Fri, 12 Apr 2019 08:36:03 -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 fmsmga107.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 12 Apr 2019 05:36:03 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.60,341,1549958400"; d="scan'208";a="135223683" Received: from mylly.fi.intel.com (HELO [10.237.72.155]) ([10.237.72.155]) by orsmga006.jf.intel.com with ESMTP; 12 Apr 2019 05:36:00 -0700 Subject: Re: [PATCH v2] 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: <1555054339-17096-1-git-send-email-f.suligoi@asem.it> From: Jarkko Nikula Message-ID: <729d9db2-de3e-e64c-862d-db8a25775b02@linux.intel.com> Date: Fri, 12 Apr 2019 15:35:38 +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: <1555054339-17096-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/12/19 10:32 AM, 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 > Reviewed-by: Jarkko Nikula > --- > > v2: - simplify the code using "DIV_ROUND_UP" > v1: - first version > > drivers/spi/spi-pxa2xx.c | 8 ++++++-- > 1 file changed, 6 insertions(+), 2 deletions(-) > > diff --git a/drivers/spi/spi-pxa2xx.c b/drivers/spi/spi-pxa2xx.c > index f7068cc..a35fdcb 100644 > --- a/drivers/spi/spi-pxa2xx.c > +++ b/drivers/spi/spi-pxa2xx.c > @@ -884,10 +884,14 @@ 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 (DIV_ROUND_UP(ssp_clk, 2 * rate) - 1) & 0xff; > else > - return (ssp_clk / rate - 1) & 0xfff; > + return (DIV_ROUND_UP(ssp_clk, rate) - 1) & 0xfff; > } > Reviewed-by: Jarkko Nikula