linux-spi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Addy Ke <addy.ke@rock-chips.com>
To: broonie@kernel.org, heiko@sntech.de, dianders@chromium.org,
	grant.likely@linaro.org, robh+dt@kernel.org, amstan@google.com,
	sonnyrao@google.com
Cc: linux-kernel@vger.kernel.org, linux-spi@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
	linux-rockchip@lists.infradead.org, devicetree@vger.kernel.org,
	olof@lixom.net, hj@rock-chips.com, kever.yang@rock-chips.com,
	xjq@rock-chips.com, huangtao@rock-chips.com, zyw@rock-chips.com,
	yzq@rock-chips.com, zhenfu.fang@rock-chips.com,
	cf@rock-chips.com, zhangqing@rock-chips.com, hl@rock-chips.com,
	wei.luo@rock-chips.com, Addy Ke <addy.ke@rock-chips.com>
Subject: [PATCH 1/2] spi/rockchip: fix bug that case spi can't go as fast as slave request
Date: Wed, 15 Oct 2014 19:25:49 +0800	[thread overview]
Message-ID: <1413372349-4254-1-git-send-email-addy.ke@rock-chips.com> (raw)
In-Reply-To: <1413372311-4203-1-git-send-email-addy.ke@rock-chips.com>

Because the minimum divisor in rk3x's spi controller is 2,
if spi_clk is less than 2 * sclk_out, we can't get the right divisor.
So we must set spi_clk again to match slave request.

Signed-off-by: Addy Ke <addy.ke@rock-chips.com>
---
 drivers/spi/spi-rockchip.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/drivers/spi/spi-rockchip.c b/drivers/spi/spi-rockchip.c
index f96ea8a..3044c6c 100644
--- a/drivers/spi/spi-rockchip.c
+++ b/drivers/spi/spi-rockchip.c
@@ -145,6 +145,9 @@
 #define RXBUSY						(1 << 0)
 #define TXBUSY						(1 << 1)
 
+/* sclk_out: spi master internal logic in rk3x can support 50Mhz */
+#define MAX_SCLK_OUT		50000000
+
 enum rockchip_ssi_type {
 	SSI_MOTO_SPI = 0,
 	SSI_TI_SSP,
@@ -496,6 +499,15 @@ static void rockchip_spi_config(struct rockchip_spi *rs)
 			dmacr |= RF_DMA_EN;
 	}
 
+	if (WARN_ON(rs->speed > MAX_SCLK_OUT))
+		rs->speed = MAX_SCLK_OUT;
+
+	/* the minimum divsor is 2 */
+	if (rs->max_freq < 2 * rs->speed) {
+		clk_set_rate(rs->spiclk, 2 * rs->speed);
+		rs->max_freq = clk_get_rate(rs->spiclk);
+	}
+
 	/* div doesn't support odd number */
 	div = max_t(u32, rs->max_freq / rs->speed, 1);
 	div = (div + 1) & 0xfffe;
-- 
1.8.3.2

  reply	other threads:[~2014-10-15 11:25 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-10-15 11:25 [PATCH 0/2] spi: fix two bugs Addy Ke
2014-10-15 11:25 ` Addy Ke [this message]
2014-10-15 13:04   ` [PATCH 1/2] spi/rockchip: fix bug that case spi can't go as fast as slave request Mark Brown
     [not found]     ` <20141015130452.GD27755-GFdadSzt00ze9xe1eoZjHA@public.gmane.org>
2014-10-16  9:16       ` addy ke
2014-10-16  9:34         ` Mark Brown
2014-10-16  9:58           ` addy ke
2014-10-16 10:26             ` Mark Brown
2014-10-15 11:26 ` [PATCH 2/2] spi/rockchip: fix bug that cause spi transfer timed out in DMA duplex mode Addy Ke
     [not found]   ` <1413372378-4309-1-git-send-email-addy.ke-TNX95d0MmH7DzftRWevZcw@public.gmane.org>
2014-10-15 13:05     ` Mark Brown
     [not found]       ` <20141015130547.GE27755-GFdadSzt00ze9xe1eoZjHA@public.gmane.org>
2014-10-16  9:26         ` addy ke
2014-10-16  9:34           ` Mark Brown

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=1413372349-4254-1-git-send-email-addy.ke@rock-chips.com \
    --to=addy.ke@rock-chips.com \
    --cc=amstan@google.com \
    --cc=broonie@kernel.org \
    --cc=cf@rock-chips.com \
    --cc=devicetree@vger.kernel.org \
    --cc=dianders@chromium.org \
    --cc=grant.likely@linaro.org \
    --cc=heiko@sntech.de \
    --cc=hj@rock-chips.com \
    --cc=hl@rock-chips.com \
    --cc=huangtao@rock-chips.com \
    --cc=kever.yang@rock-chips.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rockchip@lists.infradead.org \
    --cc=linux-spi@vger.kernel.org \
    --cc=olof@lixom.net \
    --cc=robh+dt@kernel.org \
    --cc=sonnyrao@google.com \
    --cc=wei.luo@rock-chips.com \
    --cc=xjq@rock-chips.com \
    --cc=yzq@rock-chips.com \
    --cc=zhangqing@rock-chips.com \
    --cc=zhenfu.fang@rock-chips.com \
    --cc=zyw@rock-chips.com \
    /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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).