From: Geert Uytterhoeven <geert+renesas@glider.be>
To: Mark Brown <broonie@kernel.org>
Cc: Chris Brandt <chris.brandt@renesas.com>,
linux-spi@vger.kernel.org, linux-renesas-soc@vger.kernel.org,
linux-sh@vger.kernel.org,
Geert Uytterhoeven <geert+renesas@glider.be>
Subject: [PATCH v2 4/7] spi: rspi: Increase bit rate range for RSPI on SH
Date: Wed, 19 Aug 2020 12:59:01 +0000 [thread overview]
Message-ID: <20200819125904.20938-5-geert+renesas@glider.be> (raw)
In-Reply-To: <20200819125904.20938-1-geert+renesas@glider.be>
Increase bit rate range for RSPI on legacy SH by making use of the Bit
Rate Frequency Division Setting field in Command Registers, just like is
already done on RZ/A. This decreases the lower limit by a factor of 8.
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
---
Untested due to lack of hardware, but the formulas in the datasheets for
SH7753, RZ/A1H, and RZ/A2M are the same.
v2:
- No changes.
---
drivers/spi/spi-rspi.c | 35 ++++++++++++++++++-----------------
1 file changed, 18 insertions(+), 17 deletions(-)
diff --git a/drivers/spi/spi-rspi.c b/drivers/spi/spi-rspi.c
index ad4ac867170b101a..ea3f2680d3c13e02 100644
--- a/drivers/spi/spi-rspi.c
+++ b/drivers/spi/spi-rspi.c
@@ -248,19 +248,32 @@ struct spi_ops {
u8 num_hw_ss;
};
+static void rspi_set_rate(struct rspi_data *rspi)
+{
+ unsigned long clksrc;
+ int brdv = 0, spbr;
+
+ clksrc = clk_get_rate(rspi->clk);
+ spbr = DIV_ROUND_UP(clksrc, 2 * rspi->speed_hz) - 1;
+ while (spbr > 255 && brdv < 3) {
+ brdv++;
+ spbr = DIV_ROUND_UP(spbr + 1, 2) - 1;
+ }
+
+ rspi_write8(rspi, clamp(spbr, 0, 255), RSPI_SPBR);
+ rspi->spcmd |= SPCMD_BRDV(brdv);
+}
+
/*
* functions for RSPI on legacy SH
*/
static int rspi_set_config_register(struct rspi_data *rspi, int access_size)
{
- int spbr;
-
/* Sets output mode, MOSI signal, and (optionally) loopback */
rspi_write8(rspi, rspi->sppcr, RSPI_SPPCR);
/* Sets transfer bit rate */
- spbr = DIV_ROUND_UP(clk_get_rate(rspi->clk), 2 * rspi->speed_hz) - 1;
- rspi_write8(rspi, clamp(spbr, 0, 255), RSPI_SPBR);
+ rspi_set_rate(rspi);
/* Disable dummy transmission, set 16-bit word access, 1 frame */
rspi_write8(rspi, 0, RSPI_SPDCR);
@@ -290,23 +303,11 @@ static int rspi_set_config_register(struct rspi_data *rspi, int access_size)
*/
static int rspi_rz_set_config_register(struct rspi_data *rspi, int access_size)
{
- int spbr;
- int brdv = 0;
- unsigned long clksrc;
-
/* Sets output mode, MOSI signal, and (optionally) loopback */
rspi_write8(rspi, rspi->sppcr, RSPI_SPPCR);
- clksrc = clk_get_rate(rspi->clk);
- spbr = DIV_ROUND_UP(clksrc, 2 * rspi->speed_hz) - 1;
- while (spbr > 255 && brdv < 3) {
- brdv++;
- spbr = DIV_ROUND_UP(spbr + 1, 2) - 1;
- }
-
/* Sets transfer bit rate */
- rspi_write8(rspi, clamp(spbr, 0, 255), RSPI_SPBR);
- rspi->spcmd |= SPCMD_BRDV(brdv);
+ rspi_set_rate(rspi);
/* Disable dummy transmission, set byte access */
rspi_write8(rspi, SPDCR_SPLBYTE, RSPI_SPDCR);
--
2.17.1
next prev parent reply other threads:[~2020-08-19 12:59 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-08-19 12:58 [PATCH v2 0/7] spi: rspi: Bit rate improvements Geert Uytterhoeven
2020-08-19 12:58 ` [PATCH v2 1/7] spi: rspi: Remove useless .set_config_register() check Geert Uytterhoeven
2020-08-19 12:58 ` [PATCH v2 2/7] spi: rspi: Clean up Bit Rate Division Setting handling Geert Uytterhoeven
2020-08-19 12:59 ` [PATCH v2 3/7] spi: rspi: Increase bit rate accuracy on RZ/A Geert Uytterhoeven
2020-08-19 12:59 ` Geert Uytterhoeven [this message]
2020-08-19 12:59 ` [PATCH v2 5/7] spi: rspi: Increase bit rate range for QSPI Geert Uytterhoeven
2020-08-19 12:59 ` [PATCH v2 6/7] spi: rspi: Fill in spi_transfer.effective_speed_hz Geert Uytterhoeven
2020-08-19 12:59 ` [PATCH v2 7/7] spi: rspi: Fill in controller speed limits Geert Uytterhoeven
2020-08-20 21:48 ` [PATCH v2 0/7] spi: rspi: Bit rate improvements 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=20200819125904.20938-5-geert+renesas@glider.be \
--to=geert+renesas@glider.be \
--cc=broonie@kernel.org \
--cc=chris.brandt@renesas.com \
--cc=linux-renesas-soc@vger.kernel.org \
--cc=linux-sh@vger.kernel.org \
--cc=linux-spi@vger.kernel.org \
/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).