LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Flavio Suligoi <f.suligoi@asem.it>,
	Jarkko Nikula <jarkko.nikula@linux.intel.com>,
	Mark Brown <broonie@kernel.org>, Sasha Levin <sashal@kernel.org>,
	linux-spi@vger.kernel.org
Subject: [PATCH AUTOSEL 4.4 06/92] spi: pxa2xx: fix SCR (divisor) calculation
Date: Wed, 22 May 2019 15:30:01 -0400	[thread overview]
Message-ID: <20190522193127.27079-6-sashal@kernel.org> (raw)
In-Reply-To: <20190522193127.27079-1-sashal@kernel.org>

From: Flavio Suligoi <f.suligoi@asem.it>

[ 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 <f.suligoi@asem.it>
Reviewed-by: Jarkko Nikula <jarkko.nikula@linux.intel.com>
Reviewed-by: Jarkko Nikula <jarkko.nikula@linux.intel.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 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 3cac73e4c3e4a..e87b6fc9f4c63 100644
--- a/drivers/spi/spi-pxa2xx.c
+++ b/drivers/spi/spi-pxa2xx.c
@@ -859,10 +859,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


  parent reply	other threads:[~2019-05-22 19:31 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-22 19:29 [PATCH AUTOSEL 4.4 01/92] gfs2: Fix lru_count going negative Sasha Levin
2019-05-22 19:29 ` [PATCH AUTOSEL 4.4 02/92] cxgb4: Fix error path in cxgb4_init_module Sasha Levin
2019-05-22 19:29 ` [PATCH AUTOSEL 4.4 03/92] mmc: core: Verify SD bus width Sasha Levin
2019-05-22 19:29 ` [PATCH AUTOSEL 4.4 04/92] powerpc/boot: Fix missing check of lseek() return value Sasha Levin
2019-05-22 19:30 ` [PATCH AUTOSEL 4.4 05/92] ASoC: imx: fix fiq dependencies Sasha Levin
2019-05-22 19:30 ` Sasha Levin [this message]
2019-05-22 19:30 ` [PATCH AUTOSEL 4.4 07/92] brcm80211: potential NULL dereference in brcmf_cfg80211_vndr_cmds_dcmd_handler() Sasha Levin
2019-05-22 19:30 ` [PATCH AUTOSEL 4.4 08/92] rtc: 88pm860x: prevent use-after-free on device remove Sasha Levin
2019-05-22 19:30 ` [PATCH AUTOSEL 4.4 09/92] w1: fix the resume command API Sasha Levin
2019-05-22 19:30 ` [PATCH AUTOSEL 4.4 10/92] dmaengine: pl330: _stop: clear interrupt status Sasha Levin
2019-05-22 19:30 ` [PATCH AUTOSEL 4.4 11/92] mac80211/cfg80211: update bss channel on channel switch Sasha Levin
2019-05-22 19:30 ` [PATCH AUTOSEL 4.4 12/92] driver core: platform: Fix the usage of platform device name(pdev->name) Sasha Levin
2019-05-22 19:30 ` [PATCH AUTOSEL 4.4 13/92] ASoC: fsl_sai: Update is_slave_mode with correct value Sasha Levin
2019-05-22 19:30 ` [PATCH AUTOSEL 4.4 14/92] mwifiex: prevent an array overflow Sasha Levin
2019-05-22 19:30 ` [PATCH AUTOSEL 4.4 15/92] net: cw1200: fix a NULL pointer dereference Sasha Levin
2019-05-22 19:30 ` [PATCH AUTOSEL 4.4 16/92] at76c50x-usb: Don't register led_trigger if usb_register_driver failed Sasha Levin
2019-05-22 19:30 ` [PATCH AUTOSEL 4.4 17/92] ssb: Fix possible NULL pointer dereference in ssb_host_pcmcia_exit Sasha Levin
2019-05-22 19:30 ` [PATCH AUTOSEL 4.4 18/92] bcache: return error immediately in bch_journal_replay() Sasha Levin
2019-05-22 19:30 ` [PATCH AUTOSEL 4.4 19/92] bcache: fix failure in journal relplay Sasha Levin
2019-05-22 19:30 ` [PATCH AUTOSEL 4.4 20/92] bcache: add failure check to run_cache_set() for journal replay Sasha Levin
2019-05-22 19:30 ` [PATCH AUTOSEL 4.4 21/92] bcache: avoid clang -Wunintialized warning Sasha Levin
2019-05-22 19:30 ` [PATCH AUTOSEL 4.4 22/92] RDMA/cma: Consider scope_id while binding to ipv6 ll address Sasha Levin
2019-05-22 19:30 ` [PATCH AUTOSEL 4.4 23/92] x86/build: Move _etext to actual end of .text Sasha Levin
2019-05-22 19:30 ` [PATCH AUTOSEL 4.4 24/92] smpboot: Place the __percpu annotation correctly Sasha Levin
2019-05-22 19:30 ` [PATCH AUTOSEL 4.4 25/92] x86/mm: Remove in_nmi() warning from 64-bit implementation of vmalloc_fault() Sasha Levin
2019-05-22 19:30 ` [PATCH AUTOSEL 4.4 26/92] mm/uaccess: Use 'unsigned long' to placate UBSAN warnings on older GCC versions Sasha Levin
2019-05-22 19:30 ` [PATCH AUTOSEL 4.4 27/92] HID: logitech-hidpp: use RAP instead of FAP to get the protocol version Sasha Levin
2019-05-22 19:30 ` [PATCH AUTOSEL 4.4 28/92] pinctrl: pistachio: fix leaked of_node references Sasha Levin
2019-05-22 19:30 ` [PATCH AUTOSEL 4.4 29/92] dmaengine: at_xdmac: remove BUG_ON macro in tasklet Sasha Levin
2019-05-22 19:30 ` [PATCH AUTOSEL 4.4 30/92] media: coda: clear error return value before picture run Sasha Levin
2019-05-22 19:30 ` [PATCH AUTOSEL 4.4 31/92] media: ov6650: Move v4l2_clk_get() to ov6650_video_probe() helper Sasha Levin
2019-05-22 19:30 ` [PATCH AUTOSEL 4.4 32/92] media: au0828: stop video streaming only when last user stops Sasha Levin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190522193127.27079-6-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=broonie@kernel.org \
    --cc=f.suligoi@asem.it \
    --cc=jarkko.nikula@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-spi@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    --subject='Re: [PATCH AUTOSEL 4.4 06/92] spi: pxa2xx: fix SCR (divisor) calculation' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).