mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Rasmus Villemoes <ravi@prevas.dk>
To: Colin Foster <colin.foster@in-advantage.com>, Lee Jones <lee@kernel.org>
Cc: linux-kernel@vger.kernel.org, devicetree@vger.kernel.org,
	Felix Blix Everberg <felix.blix@prevas.dk>,
	Rasmus Villemoes <ravi@prevas.dk>
Subject: [PATCH 4/8] mfd: ocelot: lift chip reset logic to ocelot-core.c
Date: Wed, 19 Mar 2025 13:30:54 +0100	[thread overview]
Message-ID: <20250319123058.452202-5-ravi@prevas.dk> (raw)
In-Reply-To: <20250319123058.452202-1-ravi@prevas.dk>

As further preparation for implementing support for mdio management,
lift the initialization of the ->gcb_regmap, the initial (and
optional) bus initialization callback, and the call of
ocelot_chip_reset() to ocelot_core_init().

Signed-off-by: Rasmus Villemoes <ravi@prevas.dk>
---
 drivers/mfd/ocelot-core.c | 28 +++++++++++++++++++++++++++-
 drivers/mfd/ocelot-spi.c  | 33 +--------------------------------
 2 files changed, 28 insertions(+), 33 deletions(-)

diff --git a/drivers/mfd/ocelot-core.c b/drivers/mfd/ocelot-core.c
index 9caab83138e59..c0ab5492c83f9 100644
--- a/drivers/mfd/ocelot-core.c
+++ b/drivers/mfd/ocelot-core.c
@@ -28,6 +28,9 @@
 
 #include "ocelot.h"
 
+#define VSC7512_CHIP_REGS_RES_START	0x71070000
+#define VSC7512_CHIP_REGS_RES_SIZE	0x14
+
 #define REG_GCB_SOFT_RST		0x0008
 
 #define BIT_SOFT_CHIP_RST		BIT(0)
@@ -123,6 +126,11 @@ int ocelot_chip_reset(struct device *dev)
 }
 EXPORT_SYMBOL_NS(ocelot_chip_reset, "MFD_OCELOT");
 
+static const struct resource vsc7512_gcb_resource =
+	DEFINE_RES_REG_NAMED(VSC7512_CHIP_REGS_RES_START,
+			     VSC7512_CHIP_REGS_RES_SIZE,
+			     "devcpu_gcb_chip_regs");
+
 static const struct resource vsc7512_miim0_resources[] = {
 	DEFINE_RES_REG_NAMED(VSC7512_MIIM0_RES_START, VSC7512_MIIM_RES_SIZE, "gcb_miim0"),
 	DEFINE_RES_REG_NAMED(VSC7512_PHY_RES_START, VSC7512_PHY_RES_SIZE, "gcb_phy"),
@@ -227,7 +235,25 @@ static void ocelot_core_try_add_regmaps(struct device *dev,
 
 int ocelot_core_init(struct device *dev)
 {
-	int i, ndevs;
+	struct ocelot_ddata *ddata = dev_get_drvdata(dev);
+	struct regmap *r;
+	int i, ndevs, err;
+
+	r = ddata->init_regmap(dev, &vsc7512_gcb_resource);
+	if (IS_ERR(r))
+		return PTR_ERR(r);
+
+	ddata->gcb_regmap = r;
+
+	if (ddata->init_bus) {
+		err = ddata->init_bus(dev);
+		if (err)
+			return dev_err_probe(dev, err, "Error initializing bus\n");
+	}
+
+	err = ocelot_chip_reset(dev);
+	if (err)
+		return dev_err_probe(dev, err, "Error resetting device\n");
 
 	ndevs = ARRAY_SIZE(vsc7512_devs);
 
diff --git a/drivers/mfd/ocelot-spi.c b/drivers/mfd/ocelot-spi.c
index 37828dd3ee95e..1844b8451e8e7 100644
--- a/drivers/mfd/ocelot-spi.c
+++ b/drivers/mfd/ocelot-spi.c
@@ -38,9 +38,6 @@
 #define VSC7512_DEVCPU_ORG_RES_START	0x71000000
 #define VSC7512_DEVCPU_ORG_RES_SIZE	0x38
 
-#define VSC7512_CHIP_REGS_RES_START	0x71070000
-#define VSC7512_CHIP_REGS_RES_SIZE	0x14
-
 #define OCELOT_SPI_BYTE_ORDER_LE 0x00000000
 #define OCELOT_SPI_BYTE_ORDER_BE 0x81818181
 
@@ -55,11 +52,6 @@ static const struct resource vsc7512_dev_cpuorg_resource =
 			     VSC7512_DEVCPU_ORG_RES_SIZE,
 			     "devcpu_org");
 
-static const struct resource vsc7512_gcb_resource =
-	DEFINE_RES_REG_NAMED(VSC7512_CHIP_REGS_RES_START,
-			     VSC7512_CHIP_REGS_RES_SIZE,
-			     "devcpu_gcb_chip_regs");
-
 static int ocelot_spi_initialize(struct device *dev)
 {
 	struct ocelot_ddata *ddata = dev_get_drvdata(dev);
@@ -246,30 +238,7 @@ static int ocelot_spi_probe(struct spi_device *spi)
 
 	ddata->cpuorg_regmap = r;
 
-	r = ocelot_spi_init_regmap(dev, &vsc7512_gcb_resource);
-	if (IS_ERR(r))
-		return PTR_ERR(r);
-
-	ddata->gcb_regmap = r;
-
-	/*
-	 * The chip must be set up for SPI before it gets initialized and reset.
-	 * This must be done before calling init, and after a chip reset is
-	 * performed.
-	 */
-	err = ocelot_spi_initialize(dev);
-	if (err)
-		return dev_err_probe(dev, err, "Error initializing SPI bus\n");
-
-	err = ocelot_chip_reset(dev);
-	if (err)
-		return dev_err_probe(dev, err, "Error resetting device\n");
-
-	err = ocelot_core_init(dev);
-	if (err)
-		return dev_err_probe(dev, err, "Error initializing Ocelot core\n");
-
-	return 0;
+	return ocelot_core_init(dev);
 }
 
 static const struct spi_device_id ocelot_spi_ids[] = {
-- 
2.49.0


  parent reply	other threads:[~2025-03-19 12:31 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-19 12:30 [PATCH 0/8] mfd: ocelot: add support for MDIO managed switch Rasmus Villemoes
2025-03-19 12:30 ` [PATCH 1/8] mfd: ocelot: refactor bus-specific regmap initialization Rasmus Villemoes
2025-03-19 20:08   ` Colin Foster
2025-03-21 11:41     ` Lee Jones
2025-03-21 12:39       ` Rasmus Villemoes
2025-03-28  8:37         ` Lee Jones
2025-03-19 12:30 ` [PATCH 2/8] mfd: ocelot: move SPI specific macros to ocelot-spi.c Rasmus Villemoes
2025-03-19 20:11   ` Colin Foster
2025-03-19 12:30 ` [PATCH 3/8] mfd: ocelot: rework SPI (re-)initialization after chip reset Rasmus Villemoes
2025-03-19 22:08   ` Colin Foster
2025-03-20 11:17     ` Rasmus Villemoes
2025-03-22 13:36       ` Colin Foster
2025-03-25 15:35         ` Rasmus Villemoes
2025-03-19 12:30 ` Rasmus Villemoes [this message]
2025-03-19 22:44   ` [PATCH 4/8] mfd: ocelot: lift chip reset logic to ocelot-core.c Colin Foster
2025-03-19 12:30 ` [PATCH 5/8] mfd: ocelot: make ocelot_chip_init() static Rasmus Villemoes
2025-03-19 22:45   ` Colin Foster
2025-03-19 12:30 ` [PATCH 6/8] mfd: ocelot: correct Kconfig dependency Rasmus Villemoes
2025-03-19 22:48   ` Colin Foster
2025-03-19 12:30 ` [PATCH 7/8] mfd: ocelot: enable support for mdio management Rasmus Villemoes
2025-03-19 12:30 ` [PATCH 8/8] dt-bindings: mfd: ocelot: mention MDIO management and add example Rasmus Villemoes
2025-03-19 13:24   ` Rob Herring (Arm)
2025-03-20 14:25     ` Rasmus Villemoes
2025-03-19 19:55 ` [PATCH 0/8] mfd: ocelot: add support for MDIO managed switch Colin Foster
2025-06-30 15:14 ` Colin Foster
2025-07-01 10:52   ` Rasmus Villemoes

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=20250319123058.452202-5-ravi@prevas.dk \
    --to=ravi@prevas.dk \
    --cc=colin.foster@in-advantage.com \
    --cc=devicetree@vger.kernel.org \
    --cc=felix.blix@prevas.dk \
    --cc=lee@kernel.org \
    --cc=linux-kernel@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

all inboxes | Powered by JetHome®