LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH 0/2] spi transfer paramater changes and baud rate calculation
@ 2021-11-24 19:33 Kamal Dasu
  2021-11-24 19:33 ` [PATCH 1/2] spi: bcm-qspi: choose sysclk setting based on requested speed Kamal Dasu
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Kamal Dasu @ 2021-11-24 19:33 UTC (permalink / raw)
  To: broonie, linux-spi, linux-kernel
  Cc: f.fainelli, bcm-kernel-feedback-list, yendapally.reddy, Kamal Dasu

The changes picks either the 27Mhz or 108MhZ system clock for spi transfers
based user requested transfer speed. Also we set the master controller transfer
parameter only if they change.

Kamal Dasu (2):
  spi: bcm-qspi: choose sysclk setting based on requested speed
  spi: bcm-qspi: set transfer parameter only if they change

 drivers/spi/spi-bcm-qspi.c | 44 ++++++++++++++++++++++++++++++++------
 1 file changed, 38 insertions(+), 6 deletions(-)

-- 
2.17.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/2] spi: bcm-qspi: choose sysclk setting based on requested speed
  2021-11-24 19:33 [PATCH 0/2] spi transfer paramater changes and baud rate calculation Kamal Dasu
@ 2021-11-24 19:33 ` Kamal Dasu
  2021-11-24 19:33 ` [PATCH 2/2] spi: bcm-qspi: set transfer parameter only if they change Kamal Dasu
  2021-11-25 13:37 ` [PATCH 0/2] spi transfer paramater changes and baud rate calculation Mark Brown
  2 siblings, 0 replies; 4+ messages in thread
From: Kamal Dasu @ 2021-11-24 19:33 UTC (permalink / raw)
  To: broonie, linux-spi, linux-kernel
  Cc: f.fainelli, bcm-kernel-feedback-list, yendapally.reddy, Kamal Dasu

Check requested speed for a given transfer before setting
27MHz or 108Mhz sysclk on SoCs that support both. This way
for baud rates below 212Khz we can use 27Mhz clock.

Signed-off-by: Kamal Dasu <kdasu.kdev@gmail.com>
---
 drivers/spi/spi-bcm-qspi.c | 32 ++++++++++++++++++++++++++------
 1 file changed, 26 insertions(+), 6 deletions(-)

diff --git a/drivers/spi/spi-bcm-qspi.c b/drivers/spi/spi-bcm-qspi.c
index f3de3305d0f5..38e6e2cb62ca 100644
--- a/drivers/spi/spi-bcm-qspi.c
+++ b/drivers/spi/spi-bcm-qspi.c
@@ -287,6 +287,18 @@ static inline int bcm_qspi_spbr_min(struct bcm_qspi *qspi)
 		return 8;
 }
 
+static u32 bcm_qspi_calc_spbr(u32 clk_speed_hz,
+			      const struct bcm_qspi_parms *xp)
+{
+	u32 spbr = 0;
+
+	/* SPBR = System Clock/(2 * SCK Baud Rate) */
+	if (xp->speed_hz)
+		spbr = clk_speed_hz / (xp->speed_hz * 2);
+
+	return spbr;
+}
+
 /* Read qspi controller register*/
 static inline u32 bcm_qspi_read(struct bcm_qspi *qspi, enum base_type type,
 				unsigned int offset)
@@ -621,9 +633,17 @@ static void bcm_qspi_hw_set_parms(struct bcm_qspi *qspi,
 			spcr |= MSPI_SPCR3_HALFDUPLEX |  MSPI_SPCR3_HDOUTTYPE;
 
 		if (bcm_qspi_has_sysclk_108(qspi)) {
-			/* SYSCLK_108 */
-			spcr |= MSPI_SPCR3_SYSCLKSEL_108;
-			qspi->base_clk = MSPI_BASE_FREQ * 4;
+			/* check requested baud rate before moving to 108Mhz */
+			spbr = bcm_qspi_calc_spbr(MSPI_BASE_FREQ * 4, xp);
+			if (spbr > QSPI_SPBR_MAX) {
+				/* use SYSCLK_27Mhz for slower baud rates */
+				spcr &= ~MSPI_SPCR3_SYSCLKSEL_MASK;
+				qspi->base_clk = MSPI_BASE_FREQ;
+			} else {
+				/* SYSCLK_108Mhz */
+				spcr |= MSPI_SPCR3_SYSCLKSEL_108;
+				qspi->base_clk = MSPI_BASE_FREQ * 4;
+			}
 		}
 
 		if (xp->bits_per_word > 16) {
@@ -649,9 +669,9 @@ static void bcm_qspi_hw_set_parms(struct bcm_qspi *qspi,
 		bcm_qspi_write(qspi, MSPI, MSPI_SPCR3, spcr);
 	}
 
-	if (xp->speed_hz)
-		spbr = qspi->base_clk / (2 * xp->speed_hz);
-
+	/* SCK Baud Rate = System Clock/(2 * SPBR) */
+	qspi->max_speed_hz = qspi->base_clk / (bcm_qspi_spbr_min(qspi) * 2);
+	spbr = bcm_qspi_calc_spbr(qspi->base_clk, xp);
 	spbr = clamp_val(spbr, bcm_qspi_spbr_min(qspi), QSPI_SPBR_MAX);
 	bcm_qspi_write(qspi, MSPI, MSPI_SPCR0_LSB, spbr);
 
-- 
2.17.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 2/2] spi: bcm-qspi: set transfer parameter only if they change
  2021-11-24 19:33 [PATCH 0/2] spi transfer paramater changes and baud rate calculation Kamal Dasu
  2021-11-24 19:33 ` [PATCH 1/2] spi: bcm-qspi: choose sysclk setting based on requested speed Kamal Dasu
@ 2021-11-24 19:33 ` Kamal Dasu
  2021-11-25 13:37 ` [PATCH 0/2] spi transfer paramater changes and baud rate calculation Mark Brown
  2 siblings, 0 replies; 4+ messages in thread
From: Kamal Dasu @ 2021-11-24 19:33 UTC (permalink / raw)
  To: broonie, linux-spi, linux-kernel
  Cc: f.fainelli, bcm-kernel-feedback-list, yendapally.reddy, Kamal Dasu

Check if the transfer parameters have changed from previous settings
before applying new parameters.

Signed-off-by: Kamal Dasu <kdasu.kdev@gmail.com>
---
 drivers/spi/spi-bcm-qspi.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/drivers/spi/spi-bcm-qspi.c b/drivers/spi/spi-bcm-qspi.c
index 38e6e2cb62ca..c9a769b8594b 100644
--- a/drivers/spi/spi-bcm-qspi.c
+++ b/drivers/spi/spi-bcm-qspi.c
@@ -598,12 +598,24 @@ static void bcm_qspi_chip_select(struct bcm_qspi *qspi, int cs)
 	qspi->curr_cs = cs;
 }
 
+static bool bcmspi_parms_did_change(const struct bcm_qspi_parms * const cur,
+				    const struct bcm_qspi_parms * const prev)
+{
+	return (cur->speed_hz != prev->speed_hz) ||
+		(cur->mode != prev->mode) ||
+		(cur->bits_per_word != prev->bits_per_word);
+}
+
+
 /* MSPI helpers */
 static void bcm_qspi_hw_set_parms(struct bcm_qspi *qspi,
 				  const struct bcm_qspi_parms *xp)
 {
 	u32 spcr, spbr = 0;
 
+	if (!bcmspi_parms_did_change(xp, &qspi->last_parms))
+		return;
+
 	if (!qspi->mspi_maj_rev)
 		/* legacy controller */
 		spcr = MSPI_MASTER_BIT;
-- 
2.17.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 0/2] spi transfer paramater changes and baud rate calculation
  2021-11-24 19:33 [PATCH 0/2] spi transfer paramater changes and baud rate calculation Kamal Dasu
  2021-11-24 19:33 ` [PATCH 1/2] spi: bcm-qspi: choose sysclk setting based on requested speed Kamal Dasu
  2021-11-24 19:33 ` [PATCH 2/2] spi: bcm-qspi: set transfer parameter only if they change Kamal Dasu
@ 2021-11-25 13:37 ` Mark Brown
  2 siblings, 0 replies; 4+ messages in thread
From: Mark Brown @ 2021-11-25 13:37 UTC (permalink / raw)
  To: linux-kernel, Kamal Dasu, linux-spi
  Cc: bcm-kernel-feedback-list, f.fainelli, yendapally.reddy

On Wed, 24 Nov 2021 14:33:51 -0500, Kamal Dasu wrote:
> The changes picks either the 27Mhz or 108MhZ system clock for spi transfers
> based user requested transfer speed. Also we set the master controller transfer
> parameter only if they change.
> 
> Kamal Dasu (2):
>   spi: bcm-qspi: choose sysclk setting based on requested speed
>   spi: bcm-qspi: set transfer parameter only if they change
> 
> [...]

Applied to

   https://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git for-next

Thanks!

[1/2] spi: bcm-qspi: choose sysclk setting based on requested speed
      commit: c74526f947ab946273939757c72499c0a5b09826
[2/2] spi: bcm-qspi: set transfer parameter only if they change
      commit: e10a6bb5f52de70c7798b720d16632d4042d2552

All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying
to this mail.

Thanks,
Mark

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-11-25 13:39 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-24 19:33 [PATCH 0/2] spi transfer paramater changes and baud rate calculation Kamal Dasu
2021-11-24 19:33 ` [PATCH 1/2] spi: bcm-qspi: choose sysclk setting based on requested speed Kamal Dasu
2021-11-24 19:33 ` [PATCH 2/2] spi: bcm-qspi: set transfer parameter only if they change Kamal Dasu
2021-11-25 13:37 ` [PATCH 0/2] spi transfer paramater changes and baud rate calculation Mark Brown

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).