devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: <kostap@marvell.com>
To: <linux-spi@vger.kernel.org>
Cc: <devicetree@vger.kernel.org>, <broonie@kernel.org>,
	<robh+dt@kernel.org>, <mw@semihalf.com>, <jaz@semihalf.com>,
	<nadavh@marvell.com>, <bpeled@marvell.com>, <stefanc@marvell.com>
Subject: [PATCH 1/3] spi: orion: enable clocks before spi_setup
Date: Thu, 17 Dec 2020 13:27:06 +0200	[thread overview]
Message-ID: <20201217112708.3473-2-kostap@marvell.com> (raw)
In-Reply-To: <20201217112708.3473-1-kostap@marvell.com>

From: Marcin Wojtas <mw@semihalf.com>

The spi-orion driver disables its clocks whenever it is not used.
In usual case during boot (i.e. using SPI flash) it is not a problem,
as the child device driver is present and probed along with
spi_register_master() execution.

However in case the child device driver is not ready
(e.g. when its type is module_spi_driver) the spi_setup() callback
can be called after the spi-orion probe. It may happen,
that as a result there will be an attempt to access controller's
registers with the clocks disabled.

Prevent such situations and make sure the clocks are on,
each time the spi_setup() is called.

Signed-off-by: Marcin Wojtas <mw@semihalf.com>
Reviewed-by: Stefan Chulski <Stefan.Chulski@cavium.com>
---
 drivers/spi/spi-orion.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/drivers/spi/spi-orion.c b/drivers/spi/spi-orion.c
index b57b8b3cc26e..3bfda4225d45 100644
--- a/drivers/spi/spi-orion.c
+++ b/drivers/spi/spi-orion.c
@@ -507,6 +507,16 @@ static int orion_spi_transfer_one(struct spi_master *master,
 
 static int orion_spi_setup(struct spi_device *spi)
 {
+	struct orion_spi *orion_spi = spi_master_get_devdata(spi->master);
+
+	/*
+	 * Make sure the clocks are enabled before
+	 * configuring the SPI controller.
+	 */
+	clk_prepare_enable(orion_spi->clk);
+	if (!IS_ERR(orion_spi->axi_clk))
+		clk_prepare_enable(orion_spi->axi_clk);
+
 	return orion_spi_setup_transfer(spi, NULL);
 }
 
-- 
2.17.1


  reply	other threads:[~2020-12-17 11:28 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-17 11:27 [PATCH 0/3] spi: new feature and fix for Marvell Orion driver kostap
2020-12-17 11:27 ` kostap [this message]
2020-12-17 13:23   ` [PATCH 1/3] spi: orion: enable clocks before spi_setup Mark Brown
2020-12-17 14:00     ` [EXT] " Kostya Porotchkin
2020-12-17 11:27 ` [PATCH 2/3] spi: orion: enable support for switching CS every transferred byte kostap
2020-12-17 13:56   ` Marcin Wojtas
2020-12-17 14:21     ` Mark Brown
2020-12-17 14:49       ` Marcin Wojtas
2020-12-17 14:15   ` Mark Brown
2020-12-17 14:48     ` Marcin Wojtas
2020-12-17 11:27 ` [PATCH 3/3] dt-bindings: spi: add support for spi-1byte-cs kostap
2020-12-17 13:38   ` 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=20201217112708.3473-2-kostap@marvell.com \
    --to=kostap@marvell.com \
    --cc=bpeled@marvell.com \
    --cc=broonie@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=jaz@semihalf.com \
    --cc=linux-spi@vger.kernel.org \
    --cc=mw@semihalf.com \
    --cc=nadavh@marvell.com \
    --cc=robh+dt@kernel.org \
    --cc=stefanc@marvell.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).