Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp156631yba; Fri, 12 Apr 2019 00:33:32 -0700 (PDT) X-Google-Smtp-Source: APXvYqxbu82zx6kA9AG9FBxFERL2qdiz2q2O6B5gi4Cyj+huYe6mO7BhD8nuhR7Mk96w/lbpenqB X-Received: by 2002:a62:304:: with SMTP id 4mr54135339pfd.99.1555054412254; Fri, 12 Apr 2019 00:33:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555054412; cv=none; d=google.com; s=arc-20160816; b=ZgRkRaV0UEPxyAPiSiDt+mexgp8yeJqAXSQrHvYpp/vn4/cFTyzB239/NFqZHgEgf5 0X4utt7lrVFpPmXTofRvM2UV4ehGCQdSpRj/WiVVha8rNSinHULJtiGZOhA5WjmC4x8J YEuF36BXTs5ZveOa0lwFwuS6Jo5RFhAwoElaVy6pj7xPUUQuEno26lTV8BwKkaLTbK0D 0u6iiSOT5C/dQWoy8vD1zCU88+prGPZm61cR9CKOPD/qmoVY1/9CW9xEXo9j1FPie150 wBZ4fgTgKcc2F3OFliTt0+UNEg8DdNMAfPH+1B7zJTVERhMiU5taDHQFVad265KW6cbf i9Xg== 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=0jGNazDO0SVGpENpo8qVcbbZ/hFUhnG2f7WODTul9TM=; b=JeGyNTtuqJkMO9fgFZ6KeIQn9BYlOpjxFXQ0FllZKI1aBcrz9i2QQf8Nks3oeFRFqR fznwwvdSFh+Cr8ZKfoEs/nm2HS10XF82/LGhZL8bxpb6uK9+cIzT4Hxq+7lUTmmG52V+ 7aizaJtptXLuceNuT/4fOkBvfeOt6xPAWUjuw7dbnAqkaMZFLtbGi7xgv0NjLjwpJKtR I8CfRxZeLAZjzWD+E9ZiYixrJsDeK61t6k5kJ+klfbNNlW3duJ6Aqhg7K2xVr/HFfaqN p0QuKJC+YVe13/AxQ1D5Jt5VQ81aZD4SuwTfeL8DUvgu0FXUQPLV3Sfz1JIhknngEnRW Umpw== 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 a15si36477494pgd.166.2019.04.12.00.33.15; Fri, 12 Apr 2019 00:33:32 -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 S1727024AbfDLHcj (ORCPT + 99 others); Fri, 12 Apr 2019 03:32:39 -0400 Received: from smtp.asem.it ([151.1.184.197]:63304 "EHLO smtp.asem.it" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726024AbfDLHcj (ORCPT ); Fri, 12 Apr 2019 03:32:39 -0400 Received: from webmail.asem.it by asem.it (smtp.asem.it) (SecurityGateway 5.5.0) with ESMTP id SG003809154.MSG for ; Fri, 12 Apr 2019 09:32:34 +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; Fri, 12 Apr 2019 09:32:33 +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; Fri, 12 Apr 2019 09:32:33 +0200 From: Flavio Suligoi To: Daniel Mack , Haojian Zhuang , Robert Jarzmik , Mark Brown , Jarkko Nikula CC: , , , Flavio Suligoi Subject: [PATCH v2] spi: pxa2xx: fix SCR (divisor) calculation Date: Fri, 12 Apr 2019 09:32:19 +0200 Message-ID: <1555054339-17096-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.0A0B0212.5CB03F12.000F,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 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; } static unsigned int pxa2xx_ssp_get_clk_div(struct driver_data *drv_data, -- 2.7.4