Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp308930ybi; Wed, 29 May 2019 21:59:08 -0700 (PDT) X-Google-Smtp-Source: APXvYqyZr4C3i8d8iWj7Oj9a5HHKeccnuSd3w7vAar2+TlWfUJmQr7UcHBKQu4NTr3eTvPSuZXnQ X-Received: by 2002:a17:90a:8c90:: with SMTP id b16mr1771817pjo.85.1559192348602; Wed, 29 May 2019 21:59:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559192348; cv=none; d=google.com; s=arc-20160816; b=HJvW+nUAlz9nuQo6RkamSOiVNJR9VcDnjmx8Tub3OzILguKcEaSjI3aHS97wEvymNM iC967IFfzKGTD1xjWQa/suaMvbifwLTyjlfdnfrbypC2SRcomvjPZ1Evp0xvB8vF3hlB VjJr55A55g/4KghBNQ86a3i9UMPXO5vjyITeKaxpoN1m0Xa+ymc7u1AT0t78jOjq3nf1 0wRaM3ZehUiIWbIer3zYA+DBz3/sHnLnOS15QmMNR9lm6O9O/sAYnunQv6ZzPFajMO/E HkDQfuCvOWKG8y12Hl9/PgumrSpmhp4tOy+0EEMXh9/oatNniyN6vtoy4fXTShFJ4PkT h87w== 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:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=5rkrgOEMqmW7siSa1B2D7hoI4aHLIrbbTNLvgwd7MFw=; b=FknZh4a3uFstErhSUuCxb7NxkXKmKRvY/SxDlyUuS86RYoQDnk9OWA16ZFVg0X3/T6 6qQ+A8VFxmwuMTb36kMwwF4v2aq9gY/dcZH1otZTk8BbkvypdLqKHXdx/uiyQLvcudHM 0J6zVeh+4FyXnXUdyf0N1gYTofoOW4kkmJwtZaBAtX8dgtOZWhFQlsPlwiVUcKHb5wHW gSCwWUuH7M+PvHKbZkNtYoSZeQV+u+0Q+LgnLKsLJogtn1jLmLftE0bYqNbyKhDkqAju nZPlsySv5O7n4H8FqVwqZ3ITwyNfrbHgMpO2Q30Sfq/nSrBt4q41+tVc+gMtMRi81i8z 0Wpg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=TP+SipxG; 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 6si2348545pfe.21.2019.05.29.21.58.52; Wed, 29 May 2019 21:59:08 -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; dkim=pass header.i=@kernel.org header.s=default header.b=TP+SipxG; 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 S2389221AbfE3E4t (ORCPT + 99 others); Thu, 30 May 2019 00:56:49 -0400 Received: from mail.kernel.org ([198.145.29.99]:46086 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727897AbfE3DKB (ORCPT ); Wed, 29 May 2019 23:10:01 -0400 Received: from localhost (ip67-88-213-2.z213-88-67.customer.algx.net [67.88.213.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 07F572449A; Thu, 30 May 2019 03:10:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1559185801; bh=GuZVLvd2ftXKMDnPVfu5+Z+fVCvqVucmujxOBuTQXHg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TP+SipxGIGBsWOJT208i7jIVe0SEVYhrlLwyogs0cpuAAbf629eTCqJ2NQ2RRIhp1 KOxUXQU1HaQBL4uPdskP5fU8N3YdZRMvzkGxWhK8g2LK/p+chjR6dDaucaW0mGZXqW xATHxmyUbgG3HeQJpygfYM5MJQFDWvirqoiQhZZA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Flavio Suligoi , Jarkko Nikula , Mark Brown , Sasha Levin Subject: [PATCH 5.1 079/405] spi: pxa2xx: fix SCR (divisor) calculation Date: Wed, 29 May 2019 20:01:17 -0700 Message-Id: <20190530030544.975474423@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190530030540.291644921@linuxfoundation.org> References: <20190530030540.291644921@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org [ Upstream commit 29f2133717c527f492933b0622a4aafe0b3cbe9e ] 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 Reviewed-by: Jarkko Nikula Signed-off-by: Mark Brown Signed-off-by: Sasha Levin --- 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 b6ddba833d021..d2076f2f468f0 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; } static unsigned int pxa2xx_ssp_get_clk_div(struct driver_data *drv_data, -- 2.20.1