All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/5] mfd: ocelot: Support the LAN9645x switch family
@ 2026-12-04 12:02 Jens Emil Schulz Østergaard
  2026-12-04 12:02 ` [PATCH v2 1/5] mfd: ocelot: Define the VSC7512 cells with the MFD_CELL_* macros Jens Emil Schulz Østergaard
                   ` (4 more replies)
  0 siblings, 5 replies; 7+ messages in thread
From: Jens Emil Schulz Østergaard @ 2026-12-04 12:02 UTC (permalink / raw)
  To: Colin Foster, Lee Jones, UNGLinuxDriver, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, Richard Cochran
  Cc: mfd, linux-kernel, netdev, devicetree,
	Jens Emil Schulz Østergaard

The Microchip LAN9645x is a family of ethernet switch chips without an
internal CPU. Like the VSC7512, the chips are controlled externally over
SPI, and the register targets of the chip are distributed as named
regmaps to child devices. This series extends the ocelot MFD driver to
the LAN9645x family, with the pin controller, the two MDIO controllers
and the switch as child devices, served by the existing pinctrl-ocelot,
mdio-mscc-miim and lan9645x DSA drivers.

Patch 1 defines the VSC7512 cells with the MFD_CELL_* macros.

Patch 2 passes the chip through the match data and selects the VSC7512
specific SPI interface, reset and child device setup by it.

Patch 3 adds a binding for the LAN9645x family.

Patch 4 adds the LAN9645x support.

Patch 5 reads LAN9645x registers in a single SPI transfer on full duplex
controllers.

Dependencies:

This series is based on net-next which includes [1]. The binding in
patch 3 references the switch binding
net/dsa/microchip,lan96455s-switch.yaml, and patch 3 adds the new
binding to the MICROCHIP LAN9645X ETHERNET SWITCH DRIVER entry in
MAINTAINERS, both added by that series.

The series therefore does not apply to for-mfd-next yet, and
dt_binding_check of patch 3 fails on a base without the switch binding.

The DSA series is expected in v7.5-rc1. The series is posted now for
review, and will be resent rebased on v7.5-rc1.

[1] https://lore.kernel.org/r/20261111-dsa_lan9645x_switch_driver_base-v17-0-83a471c5bddb@microchip.com

Signed-off-by: Jens Emil Schulz Østergaard <jensemil.schulzostergaard@microchip.com>
---
Changes in v2:
- New patch 1, define the VSC7512 cells with the MFD_CELL_* macros (Lee)
- Pass the chip as an integer through the match data, and select the
  per chip SPI setup, reset register and cells with switch statements
  instead of struct ocelot_spi_data, struct ocelot_cells and the padding
  bytes function pointer (Lee)
- Poll the soft reset with regmap_read_poll_timeout()
- Define the LAN9645x cells with the MFD_CELL_* macros (Lee)
- Compute the LAN9645x padding bytes from the bus clock in Hz instead of
  kHz, so they are always rounded up
- Drop the regmap access tables of the switch gcb and chip_top regmaps
  and struct ocelot_regmap_access (Lee)
- Single transfer read: separate transmit and receive buffers, memcpy()
  for the address and the value, comments on the three transfer read
  and the dummy buffer (Lee)
- Link to v1: https://lore.kernel.org/r/20261123-mfd-ocelot-add-lan9645x-support-v1-0-567d811fe1de@microchip.com

---
Jens Emil Schulz Østergaard (5):
      mfd: ocelot: Define the VSC7512 cells with the MFD_CELL_* macros
      mfd: ocelot: Select the chip through match data
      dt-bindings: mfd: Add the Microchip LAN9645x switch family
      mfd: ocelot: Add support for the LAN9645x switch family
      mfd: ocelot: Read LAN9645x registers in a single SPI transfer

 .../bindings/mfd/microchip,lan96455s.yaml          | 132 ++++++++++++
 MAINTAINERS                                        |   1 +
 drivers/mfd/Kconfig                                |   2 +-
 drivers/mfd/ocelot-core.c                          | 224 +++++++++++++++------
 drivers/mfd/ocelot-spi.c                           | 212 ++++++++++++++++---
 drivers/mfd/ocelot.h                               |  33 ++-
 6 files changed, 512 insertions(+), 92 deletions(-)
---
base-commit: 3b4d7f44a61b8217ed11c5df95bccfd256c52db3
change-id: 20261118-mfd-ocelot-add-lan9645x-support-9ac4042ba475

Best regards,
-- 
Jens Emil Schulz Østergaard <jensemil.schulzostergaard@microchip.com>


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

* [PATCH v2 1/5] mfd: ocelot: Define the VSC7512 cells with the MFD_CELL_* macros
  2026-12-04 12:02 [PATCH v2 0/5] mfd: ocelot: Support the LAN9645x switch family Jens Emil Schulz Østergaard
@ 2026-12-04 12:02 ` Jens Emil Schulz Østergaard
  2026-12-04 12:02 ` [PATCH v2 2/5] mfd: ocelot: Select the chip through match data Jens Emil Schulz Østergaard
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 7+ messages in thread
From: Jens Emil Schulz Østergaard @ 2026-12-04 12:02 UTC (permalink / raw)
  To: Colin Foster, Lee Jones, UNGLinuxDriver, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, Richard Cochran
  Cc: mfd, linux-kernel, netdev, devicetree,
	Jens Emil Schulz Østergaard

Define the VSC7512 child devices with MFD_CELL_OF() and
MFD_CELL_OF_REG(), which also derive the number of resources from the
resource arrays.

No functional change.

Signed-off-by: Jens Emil Schulz Østergaard <jensemil.schulzostergaard@microchip.com>
---
Changes in v2:
- New patch
---
 drivers/mfd/ocelot-core.c | 47 ++++++++++++-----------------------------------
 1 file changed, 12 insertions(+), 35 deletions(-)

diff --git a/drivers/mfd/ocelot-core.c b/drivers/mfd/ocelot-core.c
index 41aff2708854..7adf357e8bbd 100644
--- a/drivers/mfd/ocelot-core.c
+++ b/drivers/mfd/ocelot-core.c
@@ -160,41 +160,18 @@ static const struct resource vsc7512_switch_resources[] = {
 };
 
 static const struct mfd_cell vsc7512_devs[] = {
-	{
-		.name = "ocelot-pinctrl",
-		.of_compatible = "mscc,ocelot-pinctrl",
-		.num_resources = ARRAY_SIZE(vsc7512_pinctrl_resources),
-		.resources = vsc7512_pinctrl_resources,
-	}, {
-		.name = "ocelot-sgpio",
-		.of_compatible = "mscc,ocelot-sgpio",
-		.num_resources = ARRAY_SIZE(vsc7512_sgpio_resources),
-		.resources = vsc7512_sgpio_resources,
-	}, {
-		.name = "ocelot-miim0",
-		.of_compatible = "mscc,ocelot-miim",
-		.of_reg = VSC7512_MIIM0_RES_START,
-		.use_of_reg = true,
-		.num_resources = ARRAY_SIZE(vsc7512_miim0_resources),
-		.resources = vsc7512_miim0_resources,
-	}, {
-		.name = "ocelot-miim1",
-		.of_compatible = "mscc,ocelot-miim",
-		.of_reg = VSC7512_MIIM1_RES_START,
-		.use_of_reg = true,
-		.num_resources = ARRAY_SIZE(vsc7512_miim1_resources),
-		.resources = vsc7512_miim1_resources,
-	}, {
-		.name = "ocelot-serdes",
-		.of_compatible = "mscc,vsc7514-serdes",
-		.num_resources = ARRAY_SIZE(vsc7512_serdes_resources),
-		.resources = vsc7512_serdes_resources,
-	}, {
-		.name = "ocelot-ext-switch",
-		.of_compatible = "mscc,vsc7512-switch",
-		.num_resources = ARRAY_SIZE(vsc7512_switch_resources),
-		.resources = vsc7512_switch_resources,
-	},
+	MFD_CELL_OF("ocelot-pinctrl", vsc7512_pinctrl_resources, NULL, 0, 0,
+		    "mscc,ocelot-pinctrl"),
+	MFD_CELL_OF("ocelot-sgpio", vsc7512_sgpio_resources, NULL, 0, 0,
+		    "mscc,ocelot-sgpio"),
+	MFD_CELL_OF_REG("ocelot-miim0", vsc7512_miim0_resources, NULL, 0, 0,
+			"mscc,ocelot-miim", VSC7512_MIIM0_RES_START),
+	MFD_CELL_OF_REG("ocelot-miim1", vsc7512_miim1_resources, NULL, 0, 0,
+			"mscc,ocelot-miim", VSC7512_MIIM1_RES_START),
+	MFD_CELL_OF("ocelot-serdes", vsc7512_serdes_resources, NULL, 0, 0,
+		    "mscc,vsc7514-serdes"),
+	MFD_CELL_OF("ocelot-ext-switch", vsc7512_switch_resources, NULL, 0, 0,
+		    "mscc,vsc7512-switch"),
 };
 
 static void ocelot_core_try_add_regmap(struct device *dev,

-- 
2.52.0


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

* [PATCH v2 2/5] mfd: ocelot: Select the chip through match data
  2026-12-04 12:02 [PATCH v2 0/5] mfd: ocelot: Support the LAN9645x switch family Jens Emil Schulz Østergaard
  2026-12-04 12:02 ` [PATCH v2 1/5] mfd: ocelot: Define the VSC7512 cells with the MFD_CELL_* macros Jens Emil Schulz Østergaard
@ 2026-12-04 12:02 ` Jens Emil Schulz Østergaard
  2026-12-04 12:02 ` [PATCH v2 3/5] dt-bindings: mfd: Add the Microchip LAN9645x switch family Jens Emil Schulz Østergaard
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 7+ messages in thread
From: Jens Emil Schulz Østergaard @ 2026-12-04 12:02 UTC (permalink / raw)
  To: Colin Foster, Lee Jones, UNGLinuxDriver, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, Richard Cochran
  Cc: mfd, linux-kernel, netdev, devicetree,
	Jens Emil Schulz Østergaard

The SPI interface bootstrap, the chip reset and the child devices are
hardcoded for the VSC7512. Pass the chip through the SPI and OF match
data, and select the serial interface configuration target, its
registers, the IF_CFGSTAT readback value, the padding byte calculation,
the soft reset register and the child devices with a switch on the
chip. This prepares for adding the LAN9645x switch family.

The VSC7512 soft reset defines get a VSC7512 prefix. The reset is
polled with regmap_read_poll_timeout(), which returns at the first
failed read instead of retrying until the timeout.

The chip numbers start at 1, so the probe fails for a device bound
without match data. Otherwise there is no functional change.

Signed-off-by: Jens Emil Schulz Østergaard <jensemil.schulzostergaard@microchip.com>
---
Changes in v2:
- Pass the chip as an integer through the match data instead of
  struct ocelot_spi_data (Lee)
- Select the per chip SPI setup with a switch in the probe, and call the
  padding bytes calculation from it instead of through a function
  pointer (Lee)
- Select the soft reset register and the cells with switch statements
  instead of indexed tables (Lee)
- Poll the soft reset with regmap_read_poll_timeout()
- Start the chip numbers at 1, so a device without match data is
  rejected
---
 drivers/mfd/ocelot-core.c | 55 +++++++++++++++++++++++++-------------------
 drivers/mfd/ocelot-spi.c  | 58 +++++++++++++++++++++++++++++++----------------
 drivers/mfd/ocelot.h      | 15 ++++++++++++
 3 files changed, 86 insertions(+), 42 deletions(-)

diff --git a/drivers/mfd/ocelot-core.c b/drivers/mfd/ocelot-core.c
index 7adf357e8bbd..348f613d7883 100644
--- a/drivers/mfd/ocelot-core.c
+++ b/drivers/mfd/ocelot-core.c
@@ -15,7 +15,6 @@
 #include <linux/bits.h>
 #include <linux/device.h>
 #include <linux/export.h>
-#include <linux/iopoll.h>
 #include <linux/ioport.h>
 #include <linux/kernel.h>
 #include <linux/mfd/core.h>
@@ -28,9 +27,9 @@
 
 #include "ocelot.h"
 
-#define REG_GCB_SOFT_RST		0x0008
+#define VSC7512_GCB_SOFT_RST		0x0008
 
-#define BIT_SOFT_CHIP_RST		BIT(0)
+#define VSC7512_SOFT_CHIP_RST		BIT(0)
 
 #define VSC7512_MIIM0_RES_START		0x7107009c
 #define VSC7512_MIIM1_RES_START		0x710700c0
@@ -84,21 +83,21 @@
 #define VSC7512_GCB_RST_SLEEP_US	100
 #define VSC7512_GCB_RST_TIMEOUT_US	100000
 
-static int ocelot_gcb_chip_rst_status(struct ocelot_ddata *ddata)
-{
-	int val, err;
-
-	err = regmap_read(ddata->gcb_regmap, REG_GCB_SOFT_RST, &val);
-	if (err)
-		return err;
-
-	return val;
-}
-
 int ocelot_chip_reset(struct device *dev)
 {
 	struct ocelot_ddata *ddata = dev_get_drvdata(dev);
-	int ret, val;
+	unsigned int reg, val;
+	u32 mask;
+	int ret;
+
+	switch (ddata->chip) {
+	case OCELOT_CHIP_VSC7512:
+		reg = VSC7512_GCB_SOFT_RST;
+		mask = VSC7512_SOFT_CHIP_RST;
+		break;
+	default:
+		return -EINVAL;
+	}
 
 	/*
 	 * Reset the entire chip here to put it into a completely known state.
@@ -106,12 +105,13 @@ int ocelot_chip_reset(struct device *dev)
 	 * self-clears, so one write is all that is needed and wait for it to
 	 * clear.
 	 */
-	ret = regmap_write(ddata->gcb_regmap, REG_GCB_SOFT_RST, BIT_SOFT_CHIP_RST);
+	ret = regmap_write(ddata->gcb_regmap, reg, mask);
 	if (ret)
 		return ret;
 
-	return readx_poll_timeout(ocelot_gcb_chip_rst_status, ddata, val, !val,
-				  VSC7512_GCB_RST_SLEEP_US, VSC7512_GCB_RST_TIMEOUT_US);
+	return regmap_read_poll_timeout(ddata->gcb_regmap, reg, val, !val,
+					VSC7512_GCB_RST_SLEEP_US,
+					VSC7512_GCB_RST_TIMEOUT_US);
 }
 EXPORT_SYMBOL_NS(ocelot_chip_reset, "MFD_OCELOT");
 
@@ -194,14 +194,23 @@ 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);
+	const struct mfd_cell *devs;
+	int ndevs;
 
-	ndevs = ARRAY_SIZE(vsc7512_devs);
+	switch (ddata->chip) {
+	case OCELOT_CHIP_VSC7512:
+		devs = vsc7512_devs;
+		ndevs = ARRAY_SIZE(vsc7512_devs);
+		break;
+	default:
+		return -EINVAL;
+	}
 
-	for (i = 0; i < ndevs; i++)
-		ocelot_core_try_add_regmaps(dev, &vsc7512_devs[i]);
+	for (int i = 0; i < ndevs; i++)
+		ocelot_core_try_add_regmaps(dev, &devs[i]);
 
-	return devm_mfd_add_devices(dev, PLATFORM_DEVID_AUTO, vsc7512_devs, ndevs, NULL, 0, NULL);
+	return devm_mfd_add_devices(dev, PLATFORM_DEVID_AUTO, devs, ndevs, NULL, 0, NULL);
 }
 EXPORT_SYMBOL_NS(ocelot_core_init, "MFD_OCELOT");
 
diff --git a/drivers/mfd/ocelot-spi.c b/drivers/mfd/ocelot-spi.c
index 52bde8d4daf3..b02f8a5eaab9 100644
--- a/drivers/mfd/ocelot-spi.c
+++ b/drivers/mfd/ocelot-spi.c
@@ -50,6 +50,20 @@ static const struct resource vsc7512_gcb_resource =
 			     VSC7512_CHIP_REGS_RES_SIZE,
 			     "devcpu_gcb_chip_regs");
 
+static int vsc7512_spi_padding_bytes(u32 max_speed_hz)
+{
+	if (max_speed_hz <= 500000)
+		return 0;
+
+	/*
+	 * Calculation taken from the manual for IF_CFGSTAT:IF_CFG. Register
+	 * access time is 1us, so we need to configure and send out enough
+	 * padding bytes between the read request and data transmission that
+	 * lasts at least 1 microsecond.
+	 */
+	return 1 + (max_speed_hz / HZ_PER_MHZ + 2) / 8;
+}
+
 static int ocelot_spi_initialize(struct device *dev)
 {
 	struct ocelot_ddata *ddata = dev_get_drvdata(dev);
@@ -80,7 +94,7 @@ static int ocelot_spi_initialize(struct device *dev)
 	 * | 22222233 | 11112222 |   111111 |          |
 	 * | 45678901 | 67890123 | 89012345 | 01234567 |
 	 */
-	err = regmap_write(ddata->cpuorg_regmap, REG_DEV_CPUORG_IF_CTRL, val);
+	err = regmap_write(ddata->cpuorg_regmap, ddata->if_ctrl, val);
 	if (err)
 		return err;
 
@@ -90,7 +104,7 @@ static int ocelot_spi_initialize(struct device *dev)
 	 * first payload bit is shifted out too quickly, the read will fail.
 	 */
 	val = ddata->spi_padding_bytes;
-	err = regmap_write(ddata->cpuorg_regmap, REG_DEV_CPUORG_IF_CFGSTAT, val);
+	err = regmap_write(ddata->cpuorg_regmap, ddata->if_cfgstat, val);
 	if (err)
 		return err;
 
@@ -109,9 +123,9 @@ static int ocelot_spi_initialize(struct device *dev)
 	 * the registers are being accessed. Since we're accessing them via the
 	 * serial interface, it must return IF_NUM_SI.
 	 */
-	check = val | CFGSTAT_IF_NUM_SI;
+	check = val | ddata->if_cfgstat_si;
 
-	err = regmap_read(ddata->cpuorg_regmap, REG_DEV_CPUORG_IF_CFGSTAT, &val);
+	err = regmap_read(ddata->cpuorg_regmap, ddata->if_cfgstat, &val);
 	if (err)
 		return err;
 
@@ -196,6 +210,7 @@ EXPORT_SYMBOL_NS(ocelot_spi_init_regmap, "MFD_OCELOT_SPI");
 
 static int ocelot_spi_probe(struct spi_device *spi)
 {
+	const struct resource *cpuorg_res, *gcb_res;
 	struct device *dev = &spi->dev;
 	struct ocelot_ddata *ddata;
 	struct regmap *r;
@@ -205,19 +220,24 @@ static int ocelot_spi_probe(struct spi_device *spi)
 	if (!ddata)
 		return -ENOMEM;
 
+	ddata->chip = (uintptr_t)spi_get_device_match_data(spi);
+
+	switch (ddata->chip) {
+	case OCELOT_CHIP_VSC7512:
+		cpuorg_res = &vsc7512_dev_cpuorg_resource;
+		gcb_res = &vsc7512_gcb_resource;
+		ddata->if_ctrl = REG_DEV_CPUORG_IF_CTRL;
+		ddata->if_cfgstat = REG_DEV_CPUORG_IF_CFGSTAT;
+		ddata->if_cfgstat_si = CFGSTAT_IF_NUM_SI;
+		ddata->spi_padding_bytes = vsc7512_spi_padding_bytes(spi->max_speed_hz);
+		break;
+	default:
+		return dev_err_probe(dev, -ENODEV, "Unknown chip %d\n", ddata->chip);
+	}
+
 	spi_set_drvdata(spi, ddata);
 
-	if (spi->max_speed_hz <= 500000) {
-		ddata->spi_padding_bytes = 0;
-	} else {
-		/*
-		 * Calculation taken from the manual for IF_CFGSTAT:IF_CFG.
-		 * Register access time is 1us, so we need to configure and send
-		 * out enough padding bytes between the read request and data
-		 * transmission that lasts at least 1 microsecond.
-		 */
-		ddata->spi_padding_bytes = 1 + (spi->max_speed_hz / HZ_PER_MHZ + 2) / 8;
-
+	if (ddata->spi_padding_bytes) {
 		ddata->dummy_buf = devm_kzalloc(dev, ddata->spi_padding_bytes, GFP_KERNEL);
 		if (!ddata->dummy_buf)
 			return -ENOMEM;
@@ -229,13 +249,13 @@ static int ocelot_spi_probe(struct spi_device *spi)
 	if (err)
 		return dev_err_probe(&spi->dev, err, "Error performing SPI setup\n");
 
-	r = ocelot_spi_init_regmap(dev, &vsc7512_dev_cpuorg_resource);
+	r = ocelot_spi_init_regmap(dev, cpuorg_res);
 	if (IS_ERR(r))
 		return PTR_ERR(r);
 
 	ddata->cpuorg_regmap = r;
 
-	r = ocelot_spi_init_regmap(dev, &vsc7512_gcb_resource);
+	r = ocelot_spi_init_regmap(dev, gcb_res);
 	if (IS_ERR(r))
 		return PTR_ERR(r);
 
@@ -270,13 +290,13 @@ static int ocelot_spi_probe(struct spi_device *spi)
 }
 
 static const struct spi_device_id ocelot_spi_ids[] = {
-	{ .name = "vsc7512" },
+	{ .name = "vsc7512", .driver_data = OCELOT_CHIP_VSC7512 },
 	{ }
 };
 MODULE_DEVICE_TABLE(spi, ocelot_spi_ids);
 
 static const struct of_device_id ocelot_spi_of_match[] = {
-	{ .compatible = "mscc,vsc7512" },
+	{ .compatible = "mscc,vsc7512", .data = (void *)OCELOT_CHIP_VSC7512 },
 	{ }
 };
 MODULE_DEVICE_TABLE(of, ocelot_spi_of_match);
diff --git a/drivers/mfd/ocelot.h b/drivers/mfd/ocelot.h
index b8bc2f1486e2..2cfb21aa10cb 100644
--- a/drivers/mfd/ocelot.h
+++ b/drivers/mfd/ocelot.h
@@ -5,17 +5,28 @@
 #define _MFD_OCELOT_H
 
 #include <linux/kconfig.h>
+#include <linux/types.h>
 
 struct device;
 struct regmap;
 struct resource;
 
+enum ocelot_chip {
+	OCELOT_CHIP_VSC7512 = 1,
+};
+
 /**
  * struct ocelot_ddata - Private data for an external Ocelot chip
+ * @chip:		Chip family member.
  * @gcb_regmap:		General Configuration Block regmap. Used for
  *			operations like chip reset.
  * @cpuorg_regmap:	CPU Device Origin Block regmap. Used for operations
  *			like SPI bus configuration.
+ * @if_ctrl:		Offset of IF_CTRL in the cpuorg_regmap.
+ * @if_cfgstat:		Offset of IF_CFGSTAT in the cpuorg_regmap.
+ * @if_cfgstat_si:	IF_CFGSTAT interface number that is expected to read
+ *			back when the registers are accessed through the serial
+ *			interface.
  * @spi_padding_bytes:	Number of padding bytes that must be thrown out before
  *			read data gets returned. This is calculated during
  *			initialization based on bus speed.
@@ -24,8 +35,12 @@ struct resource;
  *			data of a SPI read operation.
  */
 struct ocelot_ddata {
+	enum ocelot_chip chip;
 	struct regmap *gcb_regmap;
 	struct regmap *cpuorg_regmap;
+	unsigned int if_ctrl;
+	unsigned int if_cfgstat;
+	u32 if_cfgstat_si;
 	int spi_padding_bytes;
 	void *dummy_buf;
 };

-- 
2.52.0


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

* [PATCH v2 3/5] dt-bindings: mfd: Add the Microchip LAN9645x switch family
  2026-12-04 12:02 [PATCH v2 0/5] mfd: ocelot: Support the LAN9645x switch family Jens Emil Schulz Østergaard
  2026-12-04 12:02 ` [PATCH v2 1/5] mfd: ocelot: Define the VSC7512 cells with the MFD_CELL_* macros Jens Emil Schulz Østergaard
  2026-12-04 12:02 ` [PATCH v2 2/5] mfd: ocelot: Select the chip through match data Jens Emil Schulz Østergaard
@ 2026-12-04 12:02 ` Jens Emil Schulz Østergaard
  2026-12-04 12:02 ` [PATCH v2 4/5] mfd: ocelot: Add support for the " Jens Emil Schulz Østergaard
  2026-12-04 12:02 ` [PATCH v2 5/5] mfd: ocelot: Read LAN9645x registers in a single SPI transfer Jens Emil Schulz Østergaard
  4 siblings, 0 replies; 7+ messages in thread
From: Jens Emil Schulz Østergaard @ 2026-12-04 12:02 UTC (permalink / raw)
  To: Colin Foster, Lee Jones, UNGLinuxDriver, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, Richard Cochran
  Cc: mfd, linux-kernel, netdev, devicetree,
	Jens Emil Schulz Østergaard

The LAN9645x switch is controlled externally over SPI the same way as
the VSC7512 described by mscc,ocelot.yaml, but the two families share
no child devices. Add a schema of its own for the LAN9645x.

The microchip,lan96455s compatible, the smallest SKU of the family, is
the fallback of the compatibles of the other SKUs, as in the switch
binding. The children are the microchip,lan96455f-pinctrl pin
controller, microchip,lan966x-miim MDIO buses and the switch.

Signed-off-by: Jens Emil Schulz Østergaard <jensemil.schulzostergaard@microchip.com>
---
The $ref in this binding is to net/dsa/microchip,lan96455s-switch.yaml,
and the MAINTAINERS entry extended here is MICROCHIP LAN9645X ETHERNET
SWITCH DRIVER, both added by the LAN9645x DSA series in net-next and
expected in v7.5-rc1.
---
 .../bindings/mfd/microchip,lan96455s.yaml          | 132 +++++++++++++++++++++
 MAINTAINERS                                        |   1 +
 2 files changed, 133 insertions(+)

diff --git a/Documentation/devicetree/bindings/mfd/microchip,lan96455s.yaml b/Documentation/devicetree/bindings/mfd/microchip,lan96455s.yaml
new file mode 100644
index 000000000000..82f7c6290004
--- /dev/null
+++ b/Documentation/devicetree/bindings/mfd/microchip,lan96455s.yaml
@@ -0,0 +1,132 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/mfd/microchip,lan96455s.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Microchip LAN9645x Externally-Controlled Ethernet Switch
+
+maintainers:
+  - Jens Emil Schulz Østergaard <jensemil.schulzostergaard@microchip.com>
+
+description: |
+  The LAN9645x is a family of ethernet switch chips without an internal CPU.
+  The chips are controlled externally over SPI. Besides the switch, they
+  contain a pin controller and MDIO controllers.
+
+properties:
+  compatible:
+    oneOf:
+      - const: microchip,lan96455s
+      - items:
+          - enum:
+              - microchip,lan96455f
+              - microchip,lan96457f
+              - microchip,lan96459f
+              - microchip,lan96457s
+              - microchip,lan96459s
+          - const: microchip,lan96455s
+
+  reg:
+    maxItems: 1
+
+  "#address-cells":
+    const: 1
+
+  "#size-cells":
+    const: 1
+
+patternProperties:
+  "^pinctrl@[0-9a-f]+$":
+    type: object
+    $ref: /schemas/pinctrl/mscc,ocelot-pinctrl.yaml
+    properties:
+      compatible:
+        contains:
+          const: microchip,lan96455f-pinctrl
+
+  "^mdio@[0-9a-f]+$":
+    type: object
+    $ref: /schemas/net/mscc,miim.yaml
+    properties:
+      compatible:
+        const: microchip,lan966x-miim
+
+  "^ethernet-switch@[0-9a-f]+$":
+    type: object
+    $ref: /schemas/net/dsa/microchip,lan96455s-switch.yaml
+    unevaluatedProperties: false
+
+required:
+  - compatible
+  - reg
+  - "#address-cells"
+  - "#size-cells"
+
+allOf:
+  - $ref: /schemas/spi/spi-peripheral-props.yaml#
+
+unevaluatedProperties: false
+
+examples:
+  - |
+    spi {
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        soc@0 {
+            compatible = "microchip,lan96455s";
+            reg = <0>;
+            #address-cells = <1>;
+            #size-cells = <1>;
+            spi-max-frequency = <28000000>;
+
+            ethernet-switch@4000 {
+                compatible = "microchip,lan96455s-switch";
+                reg = <0x4000 0x244>, <0x8000 0x4c>, <0xc000 0x1f0>,
+                      <0x10000 0x134>, <0x14000 0x2c8>, <0x18000 0x1910>,
+                      <0x1c000 0x468>, <0x20000 0x1480>, <0x24000 0x468>,
+                      <0x28000 0x468>, <0x2c000 0x12d4>, <0x30000 0xe4>,
+                      <0x38000 0xb8>, <0x3c000 0xb8>, <0x40000 0xb8>,
+                      <0x44000 0xb8>, <0x48000 0xb8>, <0x4c000 0xb8>,
+                      <0x50000 0xb8>, <0x54000 0xb8>, <0x58000 0xb8>,
+                      <0x100000 0xa000>, <0x120000 0x1998>, <0x140000 0x7468>;
+                reg-names = "gcb", "qs", "ptp", "chip_top", "tas", "rew", "vcap0",
+                            "mep", "vcap1", "vcap2", "sys", "hsio", "dev0", "dev1",
+                            "dev2", "dev3", "dev4", "dev5", "dev6", "dev7", "dev8",
+                            "qsys", "afi", "ana";
+
+                ethernet-ports {
+                    #address-cells = <1>;
+                    #size-cells = <0>;
+
+                    ethernet-port@0 {
+                        reg = <0>;
+                        phy-handle = <&cuphy0>;
+                        phy-mode = "gmii";
+                    };
+                };
+            };
+
+            gpio_lan9645x: pinctrl@4028 {
+                compatible = "microchip,lan96455f-pinctrl";
+                reg = <0x4028 0x68>;
+                #gpio-cells = <2>;
+                gpio-controller;
+                gpio-ranges = <&gpio_lan9645x 0 0 51>;
+            };
+
+            mdio@40bc {
+                compatible = "microchip,lan966x-miim";
+                reg = <0x40bc 0x24>;
+                #address-cells = <1>;
+                #size-cells = <0>;
+
+                cuphy0: ethernet-phy@1 {
+                    reg = <1>;
+                };
+            };
+        };
+    };
+
+...
diff --git a/MAINTAINERS b/MAINTAINERS
index 9336fa93ce38..a61791fed2ae 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -18294,6 +18294,7 @@ M:	Jens Emil Schulz Østergaard <jensemil.schulzostergaard@microchip.com>
 M:	UNGLinuxDriver@microchip.com
 L:	netdev@vger.kernel.org
 S:	Maintained
+F:	Documentation/devicetree/bindings/mfd/microchip,lan96455s.yaml
 F:	Documentation/devicetree/bindings/net/dsa/microchip,lan96455s-switch.yaml
 F:	drivers/net/dsa/microchip/lan9645x/*
 F:	include/linux/dsa/lan9645x.h

-- 
2.52.0


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

* [PATCH v2 4/5] mfd: ocelot: Add support for the LAN9645x switch family
  2026-12-04 12:02 [PATCH v2 0/5] mfd: ocelot: Support the LAN9645x switch family Jens Emil Schulz Østergaard
                   ` (2 preceding siblings ...)
  2026-12-04 12:02 ` [PATCH v2 3/5] dt-bindings: mfd: Add the Microchip LAN9645x switch family Jens Emil Schulz Østergaard
@ 2026-12-04 12:02 ` Jens Emil Schulz Østergaard
  2026-12-05 12:03   ` sashiko-bot
  2026-12-04 12:02 ` [PATCH v2 5/5] mfd: ocelot: Read LAN9645x registers in a single SPI transfer Jens Emil Schulz Østergaard
  4 siblings, 1 reply; 7+ messages in thread
From: Jens Emil Schulz Østergaard @ 2026-12-04 12:02 UTC (permalink / raw)
  To: Colin Foster, Lee Jones, UNGLinuxDriver, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, Richard Cochran
  Cc: mfd, linux-kernel, netdev, devicetree,
	Jens Emil Schulz Østergaard

The LAN9645x switch is controlled over SPI like the VSC7512, with the
serial interface configuration in the General Configuration Block
SI_REGS group.

The padding bytes cover the register access time. A read of a register
group that is mapped onto a RAM waits while the hardware uses that RAM,
so the access time depends on the register and on the traffic. Base the
padding bytes on a 2 us access time, as recommended by the chip
designers.

A soft reset returns IF_CFGSTAT.IF_CFG to its default of 15 padding
bytes, and a read with another number of padding bytes than the chip is
configured for returns wrong data. Configure 15 padding bytes before
the reset, so the reset status reads correctly both before and after
the reset takes effect, and configure the padding bytes for the bus
speed after the reset. The reset also returns IF_CTRL to big-endian,
which does not affect the poll as the reset register reads zero in
either byte order once the reset is complete.

The serial interface configuration and the soft reset register share a
target, use one regmap for both.

The switch cell gets the whole General Configuration Block and chip top
targets, so the switch driver keeps its register offsets relative to
the target. The GPIO and MIIM register groups of the other cells lie
within these targets, and the switch driver only accesses its own
registers in them.

IF_CFGSTAT.IF_CFG holds at most 15 padding bytes on both chips. Fail
the probe before the reset when the bus speed needs more.

The SPI modalias is taken from the first compatible, which is the SKU
specific one. List every SKU in the SPI device ID table, so the module
is loaded for all of them.

Signed-off-by: Jens Emil Schulz Østergaard <jensemil.schulzostergaard@microchip.com>
---
Changes in v2:
- Add the LAN9645x cases to the switch statements of the previous patch
  instead of entries in per chip tables (Lee)
- Define the cells with the MFD_CELL_* macros (Lee)
- Drop the regmap access tables of the switch gcb and chip_top regmaps
  and struct ocelot_regmap_access (Lee)
- Compute the padding bytes from the bus clock in Hz instead of kHz, so
  they are always rounded up
- Mention the 2us LAN9645x access time in the padding bytes comment
---
 drivers/mfd/Kconfig       |   2 +-
 drivers/mfd/ocelot-core.c | 122 ++++++++++++++++++++++++++++++++++++++++++++++
 drivers/mfd/ocelot-spi.c  |  77 ++++++++++++++++++++++++-----
 drivers/mfd/ocelot.h      |  13 +++--
 4 files changed, 196 insertions(+), 18 deletions(-)

diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
index 87ed55c155f0..74a5cffbdecb 100644
--- a/drivers/mfd/Kconfig
+++ b/drivers/mfd/Kconfig
@@ -1208,7 +1208,7 @@ config MFD_OCELOT
 	  through different interfaces, including SPI, I2C, and PCIe.
 
 	  Say yes here to add support for Ocelot chips (VSC7511, VSC7512,
-	  VSC7513, VSC7514) controlled externally.
+	  VSC7513, VSC7514) and LAN9645x chips controlled externally.
 
 	  To compile this driver as a module, choose M here: the module will be
 	  called ocelot-soc.
diff --git a/drivers/mfd/ocelot-core.c b/drivers/mfd/ocelot-core.c
index 348f613d7883..6b046d766a8b 100644
--- a/drivers/mfd/ocelot-core.c
+++ b/drivers/mfd/ocelot-core.c
@@ -80,6 +80,69 @@
 #define VSC7512_PORT_10_RES_START	0x71280000
 #define VSC7512_PORT_RES_SIZE		0x00010000
 
+#define LAN9645X_GCB_SOFT_RST		0x0010
+/* Despite its name, this resets the entire LAN9645x chip */
+#define LAN9645X_SOFT_SWC_RST		BIT(1)
+
+#define LAN9645X_GPIO_RES_START		0x00004028
+#define LAN9645X_GPIO_RES_SIZE		0x00000068
+
+#define LAN9645X_MIIM0_RES_START	0x00004098
+#define LAN9645X_MIIM1_RES_START	0x000040bc
+#define LAN9645X_MIIM_RES_SIZE		0x00000024
+
+#define LAN9645X_PHY_RES_START		0x00010048
+#define LAN9645X_PHY_RES_SIZE		0x00000004
+
+#define LAN9645X_QS_RES_START		0x00008000
+#define LAN9645X_QS_RES_SIZE		0x0000004c
+
+#define LAN9645X_PTP_RES_START		0x0000c000
+#define LAN9645X_PTP_RES_SIZE		0x000001f0
+
+#define LAN9645X_CHIP_TOP_RES_START	0x00010000
+#define LAN9645X_CHIP_TOP_RES_SIZE	0x00000134
+
+#define LAN9645X_TAS_RES_START		0x00014000
+#define LAN9645X_TAS_RES_SIZE		0x000002c8
+
+#define LAN9645X_REW_RES_START		0x00018000
+#define LAN9645X_REW_RES_SIZE		0x00001910
+
+#define LAN9645X_MEP_RES_START		0x00020000
+#define LAN9645X_MEP_RES_SIZE		0x00001480
+
+#define LAN9645X_SYS_RES_START		0x0002c000
+#define LAN9645X_SYS_RES_SIZE		0x000012d4
+
+#define LAN9645X_HSIO_RES_START		0x00030000
+#define LAN9645X_HSIO_RES_SIZE		0x000000e4
+
+#define LAN9645X_QSYS_RES_START		0x00100000
+#define LAN9645X_QSYS_RES_SIZE		0x0000a000
+
+#define LAN9645X_AFI_RES_START		0x00120000
+#define LAN9645X_AFI_RES_SIZE		0x00001998
+
+#define LAN9645X_ANA_RES_START		0x00140000
+#define LAN9645X_ANA_RES_SIZE		0x00007468
+
+#define LAN9645X_VCAP0_RES_START	0x0001c000
+#define LAN9645X_VCAP1_RES_START	0x00024000
+#define LAN9645X_VCAP2_RES_START	0x00028000
+#define LAN9645X_VCAP_RES_SIZE		0x00000468
+
+#define LAN9645X_DEV_0_RES_START	0x00038000
+#define LAN9645X_DEV_1_RES_START	0x0003c000
+#define LAN9645X_DEV_2_RES_START	0x00040000
+#define LAN9645X_DEV_3_RES_START	0x00044000
+#define LAN9645X_DEV_4_RES_START	0x00048000
+#define LAN9645X_DEV_5_RES_START	0x0004c000
+#define LAN9645X_DEV_6_RES_START	0x00050000
+#define LAN9645X_DEV_7_RES_START	0x00054000
+#define LAN9645X_DEV_8_RES_START	0x00058000
+#define LAN9645X_DEV_RES_SIZE		0x000000b8
+
 #define VSC7512_GCB_RST_SLEEP_US	100
 #define VSC7512_GCB_RST_TIMEOUT_US	100000
 
@@ -95,6 +158,10 @@ int ocelot_chip_reset(struct device *dev)
 		reg = VSC7512_GCB_SOFT_RST;
 		mask = VSC7512_SOFT_CHIP_RST;
 		break;
+	case OCELOT_CHIP_LAN9645X:
+		reg = LAN9645X_GCB_SOFT_RST;
+		mask = LAN9645X_SOFT_SWC_RST;
+		break;
 	default:
 		return -EINVAL;
 	}
@@ -174,6 +241,57 @@ static const struct mfd_cell vsc7512_devs[] = {
 		    "mscc,vsc7512-switch"),
 };
 
+static const struct resource lan9645x_pinctrl_resources[] = {
+	DEFINE_RES_REG_NAMED(LAN9645X_GPIO_RES_START, LAN9645X_GPIO_RES_SIZE, "gcb_gpio"),
+};
+
+static const struct resource lan9645x_miim0_resources[] = {
+	DEFINE_RES_REG_NAMED(LAN9645X_MIIM0_RES_START, LAN9645X_MIIM_RES_SIZE, "gcb_miim0"),
+};
+
+static const struct resource lan9645x_miim1_resources[] = {
+	DEFINE_RES_REG_NAMED(LAN9645X_MIIM1_RES_START, LAN9645X_MIIM_RES_SIZE, "gcb_miim1"),
+	DEFINE_RES_REG_NAMED(LAN9645X_PHY_RES_START, LAN9645X_PHY_RES_SIZE, "gcb_phy"),
+};
+
+static const struct resource lan9645x_switch_resources[] = {
+	DEFINE_RES_REG_NAMED(LAN9645X_GCB_RES_START, LAN9645X_GCB_RES_SIZE, "gcb"),
+	DEFINE_RES_REG_NAMED(LAN9645X_QS_RES_START, LAN9645X_QS_RES_SIZE, "qs"),
+	DEFINE_RES_REG_NAMED(LAN9645X_PTP_RES_START, LAN9645X_PTP_RES_SIZE, "ptp"),
+	DEFINE_RES_REG_NAMED(LAN9645X_CHIP_TOP_RES_START, LAN9645X_CHIP_TOP_RES_SIZE, "chip_top"),
+	DEFINE_RES_REG_NAMED(LAN9645X_TAS_RES_START, LAN9645X_TAS_RES_SIZE, "tas"),
+	DEFINE_RES_REG_NAMED(LAN9645X_REW_RES_START, LAN9645X_REW_RES_SIZE, "rew"),
+	DEFINE_RES_REG_NAMED(LAN9645X_VCAP0_RES_START, LAN9645X_VCAP_RES_SIZE, "vcap0"),
+	DEFINE_RES_REG_NAMED(LAN9645X_MEP_RES_START, LAN9645X_MEP_RES_SIZE, "mep"),
+	DEFINE_RES_REG_NAMED(LAN9645X_VCAP1_RES_START, LAN9645X_VCAP_RES_SIZE, "vcap1"),
+	DEFINE_RES_REG_NAMED(LAN9645X_VCAP2_RES_START, LAN9645X_VCAP_RES_SIZE, "vcap2"),
+	DEFINE_RES_REG_NAMED(LAN9645X_SYS_RES_START, LAN9645X_SYS_RES_SIZE, "sys"),
+	DEFINE_RES_REG_NAMED(LAN9645X_HSIO_RES_START, LAN9645X_HSIO_RES_SIZE, "hsio"),
+	DEFINE_RES_REG_NAMED(LAN9645X_DEV_0_RES_START, LAN9645X_DEV_RES_SIZE, "dev0"),
+	DEFINE_RES_REG_NAMED(LAN9645X_DEV_1_RES_START, LAN9645X_DEV_RES_SIZE, "dev1"),
+	DEFINE_RES_REG_NAMED(LAN9645X_DEV_2_RES_START, LAN9645X_DEV_RES_SIZE, "dev2"),
+	DEFINE_RES_REG_NAMED(LAN9645X_DEV_3_RES_START, LAN9645X_DEV_RES_SIZE, "dev3"),
+	DEFINE_RES_REG_NAMED(LAN9645X_DEV_4_RES_START, LAN9645X_DEV_RES_SIZE, "dev4"),
+	DEFINE_RES_REG_NAMED(LAN9645X_DEV_5_RES_START, LAN9645X_DEV_RES_SIZE, "dev5"),
+	DEFINE_RES_REG_NAMED(LAN9645X_DEV_6_RES_START, LAN9645X_DEV_RES_SIZE, "dev6"),
+	DEFINE_RES_REG_NAMED(LAN9645X_DEV_7_RES_START, LAN9645X_DEV_RES_SIZE, "dev7"),
+	DEFINE_RES_REG_NAMED(LAN9645X_DEV_8_RES_START, LAN9645X_DEV_RES_SIZE, "dev8"),
+	DEFINE_RES_REG_NAMED(LAN9645X_QSYS_RES_START, LAN9645X_QSYS_RES_SIZE, "qsys"),
+	DEFINE_RES_REG_NAMED(LAN9645X_AFI_RES_START, LAN9645X_AFI_RES_SIZE, "afi"),
+	DEFINE_RES_REG_NAMED(LAN9645X_ANA_RES_START, LAN9645X_ANA_RES_SIZE, "ana"),
+};
+
+static const struct mfd_cell lan9645x_devs[] = {
+	MFD_CELL_OF("lan9645x-pinctrl", lan9645x_pinctrl_resources, NULL, 0, 0,
+		    "microchip,lan96455f-pinctrl"),
+	MFD_CELL_OF_REG("lan9645x-miim0", lan9645x_miim0_resources, NULL, 0, 0,
+			"microchip,lan966x-miim", LAN9645X_MIIM0_RES_START),
+	MFD_CELL_OF_REG("lan9645x-miim1", lan9645x_miim1_resources, NULL, 0, 0,
+			"microchip,lan966x-miim", LAN9645X_MIIM1_RES_START),
+	MFD_CELL_OF("lan9645x-switch", lan9645x_switch_resources, NULL, 0, 0,
+		    "microchip,lan96455s-switch"),
+};
+
 static void ocelot_core_try_add_regmap(struct device *dev,
 				       const struct resource *res)
 {
@@ -203,6 +321,10 @@ int ocelot_core_init(struct device *dev)
 		devs = vsc7512_devs;
 		ndevs = ARRAY_SIZE(vsc7512_devs);
 		break;
+	case OCELOT_CHIP_LAN9645X:
+		devs = lan9645x_devs;
+		ndevs = ARRAY_SIZE(lan9645x_devs);
+		break;
 	default:
 		return -EINVAL;
 	}
diff --git a/drivers/mfd/ocelot-spi.c b/drivers/mfd/ocelot-spi.c
index b02f8a5eaab9..eb040be91204 100644
--- a/drivers/mfd/ocelot-spi.c
+++ b/drivers/mfd/ocelot-spi.c
@@ -3,10 +3,10 @@
  * SPI core driver for the Ocelot chip family.
  *
  * This driver will handle everything necessary to allow for communication over
- * SPI to the VSC7511, VSC7512, VSC7513 and VSC7514 chips. The main functions
- * are to prepare the chip's SPI interface for a specific bus speed, and a host
- * processor's endianness. This will create and distribute regmaps for any
- * children.
+ * SPI to the VSC7511, VSC7512, VSC7513 and VSC7514 chips and the LAN9645x
+ * family. The main functions are to prepare the chip's SPI interface for a
+ * specific bus speed, and a host processor's endianness. This will create and
+ * distribute regmaps for any children.
  *
  * Copyright 2021-2022 Innovative Advantage Inc.
  *
@@ -40,6 +40,13 @@
 #define VSC7512_CHIP_REGS_RES_START	0x71070000
 #define VSC7512_CHIP_REGS_RES_SIZE	0x14
 
+#define LAN9645X_IF_CTRL		0x1c
+#define LAN9645X_IF_CFGSTAT		0x20
+#define LAN9645X_RESET_PADDING_BYTES	15
+#define LAN9645X_REG_ACCESS_TIME_US	2
+
+#define OCELOT_SPI_MAX_PADDING_BYTES	15
+
 static const struct resource vsc7512_dev_cpuorg_resource =
 	DEFINE_RES_REG_NAMED(VSC7512_DEVCPU_ORG_RES_START,
 			     VSC7512_DEVCPU_ORG_RES_SIZE,
@@ -50,6 +57,10 @@ static const struct resource vsc7512_gcb_resource =
 			     VSC7512_CHIP_REGS_RES_SIZE,
 			     "devcpu_gcb_chip_regs");
 
+static const struct resource lan9645x_gcb_resource =
+	DEFINE_RES_REG_NAMED(LAN9645X_GCB_RES_START, LAN9645X_GCB_RES_SIZE,
+			     "devcpu_gcb");
+
 static int vsc7512_spi_padding_bytes(u32 max_speed_hz)
 {
 	if (max_speed_hz <= 500000)
@@ -64,6 +75,16 @@ static int vsc7512_spi_padding_bytes(u32 max_speed_hz)
 	return 1 + (max_speed_hz / HZ_PER_MHZ + 2) / 8;
 }
 
+static int lan9645x_spi_padding_bytes(u32 max_speed_hz)
+{
+	/*
+	 * The datasheet gives the maximum SPI clock for a number of padding
+	 * bytes as (IF_CFGSTAT.IF_CFG * 8 - 1.5) / access_time.
+	 */
+	return DIV_ROUND_UP_ULL((u64)max_speed_hz * LAN9645X_REG_ACCESS_TIME_US + 1500000,
+				8000000);
+}
+
 static int ocelot_spi_initialize(struct device *dev)
 {
 	struct ocelot_ddata *ddata = dev_get_drvdata(dev);
@@ -100,8 +121,9 @@ static int ocelot_spi_initialize(struct device *dev)
 
 	/*
 	 * Apply the number of padding bytes between a read request and the data
-	 * payload. Some registers have access times of up to 1us, so if the
-	 * first payload bit is shifted out too quickly, the read will fail.
+	 * payload. Some registers have access times of up to 1us on the VSC7512
+	 * and 2us on the LAN9645x, so if the first payload bit is shifted out
+	 * too quickly, the read will fail.
 	 */
 	val = ddata->spi_padding_bytes;
 	err = regmap_write(ddata->cpuorg_regmap, ddata->if_cfgstat, val);
@@ -121,7 +143,8 @@ static int ocelot_spi_initialize(struct device *dev)
 	 *
 	 * The last check is for bits 31:24, which define the interface by which
 	 * the registers are being accessed. Since we're accessing them via the
-	 * serial interface, it must return IF_NUM_SI.
+	 * serial interface, it must return IF_NUM_SI. LAN9645x does not have
+	 * this field.
 	 */
 	check = val | ddata->if_cfgstat_si;
 
@@ -211,6 +234,7 @@ EXPORT_SYMBOL_NS(ocelot_spi_init_regmap, "MFD_OCELOT_SPI");
 static int ocelot_spi_probe(struct spi_device *spi)
 {
 	const struct resource *cpuorg_res, *gcb_res;
+	int padding, reset_padding = 0, dummy_len;
 	struct device *dev = &spi->dev;
 	struct ocelot_ddata *ddata;
 	struct regmap *r;
@@ -229,7 +253,15 @@ static int ocelot_spi_probe(struct spi_device *spi)
 		ddata->if_ctrl = REG_DEV_CPUORG_IF_CTRL;
 		ddata->if_cfgstat = REG_DEV_CPUORG_IF_CFGSTAT;
 		ddata->if_cfgstat_si = CFGSTAT_IF_NUM_SI;
-		ddata->spi_padding_bytes = vsc7512_spi_padding_bytes(spi->max_speed_hz);
+		padding = vsc7512_spi_padding_bytes(spi->max_speed_hz);
+		break;
+	case OCELOT_CHIP_LAN9645X:
+		cpuorg_res = &lan9645x_gcb_resource;
+		gcb_res = &lan9645x_gcb_resource;
+		ddata->if_ctrl = LAN9645X_IF_CTRL;
+		ddata->if_cfgstat = LAN9645X_IF_CFGSTAT;
+		reset_padding = LAN9645X_RESET_PADDING_BYTES;
+		padding = lan9645x_spi_padding_bytes(spi->max_speed_hz);
 		break;
 	default:
 		return dev_err_probe(dev, -ENODEV, "Unknown chip %d\n", ddata->chip);
@@ -237,8 +269,14 @@ static int ocelot_spi_probe(struct spi_device *spi)
 
 	spi_set_drvdata(spi, ddata);
 
-	if (ddata->spi_padding_bytes) {
-		ddata->dummy_buf = devm_kzalloc(dev, ddata->spi_padding_bytes, GFP_KERNEL);
+	if (padding > OCELOT_SPI_MAX_PADDING_BYTES)
+		return dev_err_probe(dev, -EINVAL,
+				     "SPI clock of %u Hz needs more than %d padding bytes\n",
+				     spi->max_speed_hz, OCELOT_SPI_MAX_PADDING_BYTES);
+
+	dummy_len = max(padding, reset_padding);
+	if (dummy_len) {
+		ddata->dummy_buf = devm_kzalloc(dev, dummy_len, GFP_KERNEL);
 		if (!ddata->dummy_buf)
 			return -ENOMEM;
 	}
@@ -255,9 +293,11 @@ static int ocelot_spi_probe(struct spi_device *spi)
 
 	ddata->cpuorg_regmap = r;
 
-	r = ocelot_spi_init_regmap(dev, gcb_res);
-	if (IS_ERR(r))
-		return PTR_ERR(r);
+	if (gcb_res != cpuorg_res) {
+		r = ocelot_spi_init_regmap(dev, gcb_res);
+		if (IS_ERR(r))
+			return PTR_ERR(r);
+	}
 
 	ddata->gcb_regmap = r;
 
@@ -266,6 +306,8 @@ static int ocelot_spi_probe(struct spi_device *spi)
 	 * This must be done before calling init, and after a chip reset is
 	 * performed.
 	 */
+	ddata->spi_padding_bytes = reset_padding ?: padding;
+
 	err = ocelot_spi_initialize(dev);
 	if (err)
 		return dev_err_probe(dev, err, "Error initializing SPI bus\n");
@@ -278,6 +320,8 @@ static int ocelot_spi_probe(struct spi_device *spi)
 	 * A chip reset will clear the SPI configuration, so it needs to be done
 	 * again before we can access any registers.
 	 */
+	ddata->spi_padding_bytes = padding;
+
 	err = ocelot_spi_initialize(dev);
 	if (err)
 		return dev_err_probe(dev, err, "Error initializing SPI bus after reset\n");
@@ -290,12 +334,19 @@ static int ocelot_spi_probe(struct spi_device *spi)
 }
 
 static const struct spi_device_id ocelot_spi_ids[] = {
+	{ .name = "lan96455f", .driver_data = OCELOT_CHIP_LAN9645X },
+	{ .name = "lan96455s", .driver_data = OCELOT_CHIP_LAN9645X },
+	{ .name = "lan96457f", .driver_data = OCELOT_CHIP_LAN9645X },
+	{ .name = "lan96457s", .driver_data = OCELOT_CHIP_LAN9645X },
+	{ .name = "lan96459f", .driver_data = OCELOT_CHIP_LAN9645X },
+	{ .name = "lan96459s", .driver_data = OCELOT_CHIP_LAN9645X },
 	{ .name = "vsc7512", .driver_data = OCELOT_CHIP_VSC7512 },
 	{ }
 };
 MODULE_DEVICE_TABLE(spi, ocelot_spi_ids);
 
 static const struct of_device_id ocelot_spi_of_match[] = {
+	{ .compatible = "microchip,lan96455s", .data = (void *)OCELOT_CHIP_LAN9645X },
 	{ .compatible = "mscc,vsc7512", .data = (void *)OCELOT_CHIP_VSC7512 },
 	{ }
 };
diff --git a/drivers/mfd/ocelot.h b/drivers/mfd/ocelot.h
index 2cfb21aa10cb..802a7db1722e 100644
--- a/drivers/mfd/ocelot.h
+++ b/drivers/mfd/ocelot.h
@@ -11,8 +11,12 @@ struct device;
 struct regmap;
 struct resource;
 
+#define LAN9645X_GCB_RES_START		0x00004000
+#define LAN9645X_GCB_RES_SIZE		0x00000244
+
 enum ocelot_chip {
 	OCELOT_CHIP_VSC7512 = 1,
+	OCELOT_CHIP_LAN9645X,
 };
 
 /**
@@ -29,10 +33,11 @@ enum ocelot_chip {
  *			interface.
  * @spi_padding_bytes:	Number of padding bytes that must be thrown out before
  *			read data gets returned. This is calculated during
- *			initialization based on bus speed.
- * @dummy_buf:		Zero-filled buffer of spi_padding_bytes size. The dummy
- *			bytes that will be sent out between the address and
- *			data of a SPI read operation.
+ *			initialization based on bus speed, or set to the
+ *			reset default of the chip around a chip reset.
+ * @dummy_buf:		Zero-filled buffer of at least spi_padding_bytes size.
+ *			The dummy bytes that will be sent out between the
+ *			address and data of a SPI read operation.
  */
 struct ocelot_ddata {
 	enum ocelot_chip chip;

-- 
2.52.0


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

* [PATCH v2 5/5] mfd: ocelot: Read LAN9645x registers in a single SPI transfer
  2026-12-04 12:02 [PATCH v2 0/5] mfd: ocelot: Support the LAN9645x switch family Jens Emil Schulz Østergaard
                   ` (3 preceding siblings ...)
  2026-12-04 12:02 ` [PATCH v2 4/5] mfd: ocelot: Add support for the " Jens Emil Schulz Østergaard
@ 2026-12-04 12:02 ` Jens Emil Schulz Østergaard
  4 siblings, 0 replies; 7+ messages in thread
From: Jens Emil Schulz Østergaard @ 2026-12-04 12:02 UTC (permalink / raw)
  To: Colin Foster, Lee Jones, UNGLinuxDriver, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, Richard Cochran
  Cc: mfd, linux-kernel, netdev, devicetree,
	Jens Emil Schulz Østergaard

A register read is three SPI transfers: the address, the padding bytes
and the value. The SPI controller handles each transfer separately, with
its own setup and interrupt.

Read the address, the padding bytes and the value of a LAN9645x register
in one full duplex transfer instead, which removes the handling of two
transfers from every read. The three transfer read works on the
LAN9645x as well, this only reduces the cost of a read. The transmit
and receive buffers are allocated per regmap, so the regmap lock
serializes their use. The transmit buffer stays zero after the
address, so a read only copies the address into it.

With the interrupt driven Atmel SPI controller of a LAN966x host at
25 MHz and a GPIO chip select, a register read takes 35.8 us instead of
62.2 us, with a standard deviation below 0.1 us over seven runs of
13800 reads.

Half duplex controllers and devices in 3-wire mode cannot transmit and
receive in one transfer, so fall back to the three transfer read for
them.

Signed-off-by: Jens Emil Schulz Østergaard <jensemil.schulzostergaard@microchip.com>
---
Changes in v2:
- Use separate transmit and receive buffers, so a read no longer clears
  the padding bytes (Lee)
- Copy the address and the value with memcpy() (Lee)
- Comment the three transfer read and the dummy buffer allocation (Lee)
- Decide on the single transfer read once in the probe instead of
  looking up the match data per regmap
---
 drivers/mfd/ocelot-spi.c | 87 ++++++++++++++++++++++++++++++++++++++++++++++--
 drivers/mfd/ocelot.h     |  7 +++-
 2 files changed, 91 insertions(+), 3 deletions(-)

diff --git a/drivers/mfd/ocelot-spi.c b/drivers/mfd/ocelot-spi.c
index eb040be91204..dd586f477339 100644
--- a/drivers/mfd/ocelot-spi.c
+++ b/drivers/mfd/ocelot-spi.c
@@ -13,6 +13,7 @@
  * Author: Colin Foster <colin.foster@in-advantage.com>
  */
 
+#include <linux/cache.h>
 #include <linux/device.h>
 #include <linux/err.h>
 #include <linux/errno.h>
@@ -45,7 +46,12 @@
 #define LAN9645X_RESET_PADDING_BYTES	15
 #define LAN9645X_REG_ACCESS_TIME_US	2
 
+#define OCELOT_SPI_ADDR_SIZE		3
 #define OCELOT_SPI_MAX_PADDING_BYTES	15
+#define OCELOT_SPI_VAL_SIZE		4
+#define OCELOT_SPI_XFER_BUF_SIZE	(OCELOT_SPI_ADDR_SIZE + \
+					 OCELOT_SPI_MAX_PADDING_BYTES + \
+					 OCELOT_SPI_VAL_SIZE)
 
 static const struct resource vsc7512_dev_cpuorg_resource =
 	DEFINE_RES_REG_NAMED(VSC7512_DEVCPU_ORG_RES_START,
@@ -61,6 +67,12 @@ static const struct resource lan9645x_gcb_resource =
 	DEFINE_RES_REG_NAMED(LAN9645X_GCB_RES_START, LAN9645X_GCB_RES_SIZE,
 			     "devcpu_gcb");
 
+struct ocelot_spi_regmap_ctx {
+	struct device *dev;
+	u8 tx[OCELOT_SPI_XFER_BUF_SIZE] __aligned(ARCH_DMA_MINALIGN);
+	u8 rx[OCELOT_SPI_XFER_BUF_SIZE] __aligned(ARCH_DMA_MINALIGN);
+};
+
 static int vsc7512_spi_padding_bytes(u32 max_speed_hz)
 {
 	if (max_speed_hz <= 500000)
@@ -217,8 +229,60 @@ static const struct regmap_bus ocelot_spi_regmap_bus = {
 	.read = ocelot_spi_regmap_bus_read,
 };
 
+static int ocelot_spi_regmap_xfer_read(void *context, const void *reg,
+				       size_t reg_size, void *val,
+				       size_t val_size)
+{
+	struct ocelot_spi_regmap_ctx *ctx = context;
+	struct ocelot_ddata *ddata = dev_get_drvdata(ctx->dev);
+	struct spi_transfer xfer = {};
+	size_t off;
+	int err;
+
+	if (reg_size != OCELOT_SPI_ADDR_SIZE || val_size != OCELOT_SPI_VAL_SIZE ||
+	    ddata->spi_padding_bytes > OCELOT_SPI_MAX_PADDING_BYTES)
+		return -EINVAL;
+
+	off = OCELOT_SPI_ADDR_SIZE + ddata->spi_padding_bytes;
+
+	memcpy(ctx->tx, reg, OCELOT_SPI_ADDR_SIZE);
+
+	xfer.tx_buf = ctx->tx;
+	xfer.rx_buf = ctx->rx;
+	xfer.len = off + OCELOT_SPI_VAL_SIZE;
+
+	err = spi_sync_transfer(to_spi_device(ctx->dev), &xfer, 1);
+	if (err)
+		return err;
+
+	memcpy(val, &ctx->rx[off], OCELOT_SPI_VAL_SIZE);
+
+	return 0;
+}
+
+static int ocelot_spi_regmap_xfer_write(void *context, const void *data,
+					size_t count)
+{
+	struct ocelot_spi_regmap_ctx *ctx = context;
+
+	return spi_write(to_spi_device(ctx->dev), data, count);
+}
+
+static const struct regmap_bus ocelot_spi_regmap_xfer_bus = {
+	.write = ocelot_spi_regmap_xfer_write,
+	.read = ocelot_spi_regmap_xfer_read,
+};
+
+static bool ocelot_spi_full_duplex(struct spi_device *spi)
+{
+	return !(spi->controller->flags & SPI_CONTROLLER_HALF_DUPLEX) &&
+	       !(spi->mode & SPI_3WIRE);
+}
+
 struct regmap *ocelot_spi_init_regmap(struct device *dev, const struct resource *res)
 {
+	struct ocelot_ddata *ddata = dev_get_drvdata(dev);
+	struct ocelot_spi_regmap_ctx *ctx;
 	struct regmap_config regmap_config;
 
 	memcpy(&regmap_config, &ocelot_spi_regmap_config, sizeof(regmap_config));
@@ -227,7 +291,20 @@ struct regmap *ocelot_spi_init_regmap(struct device *dev, const struct resource
 	regmap_config.max_register = resource_size(res) - 1;
 	regmap_config.reg_base = res->start;
 
-	return devm_regmap_init(dev, &ocelot_spi_regmap_bus, dev, &regmap_config);
+	/*
+	 * Without single transfer reads, the address, the padding bytes and
+	 * the value of a read are sent as three transfers.
+	 */
+	if (!ddata->single_xfer_read)
+		return devm_regmap_init(dev, &ocelot_spi_regmap_bus, dev, &regmap_config);
+
+	ctx = devm_kzalloc_obj(dev, *ctx);
+	if (!ctx)
+		return ERR_PTR(-ENOMEM);
+
+	ctx->dev = dev;
+
+	return devm_regmap_init(dev, &ocelot_spi_regmap_xfer_bus, ctx, &regmap_config);
 }
 EXPORT_SYMBOL_NS(ocelot_spi_init_regmap, "MFD_OCELOT_SPI");
 
@@ -260,6 +337,7 @@ static int ocelot_spi_probe(struct spi_device *spi)
 		gcb_res = &lan9645x_gcb_resource;
 		ddata->if_ctrl = LAN9645X_IF_CTRL;
 		ddata->if_cfgstat = LAN9645X_IF_CFGSTAT;
+		ddata->single_xfer_read = ocelot_spi_full_duplex(spi);
 		reset_padding = LAN9645X_RESET_PADDING_BYTES;
 		padding = lan9645x_spi_padding_bytes(spi->max_speed_hz);
 		break;
@@ -274,8 +352,13 @@ static int ocelot_spi_probe(struct spi_device *spi)
 				     "SPI clock of %u Hz needs more than %d padding bytes\n",
 				     spi->max_speed_hz, OCELOT_SPI_MAX_PADDING_BYTES);
 
+	/*
+	 * A single transfer read sends the padding bytes from the transfer
+	 * buffer of its regmap, so the dummy buffer is only needed for reads
+	 * in three transfers.
+	 */
 	dummy_len = max(padding, reset_padding);
-	if (dummy_len) {
+	if (!ddata->single_xfer_read && dummy_len) {
 		ddata->dummy_buf = devm_kzalloc(dev, dummy_len, GFP_KERNEL);
 		if (!ddata->dummy_buf)
 			return -ENOMEM;
diff --git a/drivers/mfd/ocelot.h b/drivers/mfd/ocelot.h
index 802a7db1722e..99909a109e1d 100644
--- a/drivers/mfd/ocelot.h
+++ b/drivers/mfd/ocelot.h
@@ -35,9 +35,13 @@ enum ocelot_chip {
  *			read data gets returned. This is calculated during
  *			initialization based on bus speed, or set to the
  *			reset default of the chip around a chip reset.
+ * @single_xfer_read:	Read a register in one full duplex SPI transfer instead
+ *			of separate transfers for the address, the padding
+ *			bytes and the value.
  * @dummy_buf:		Zero-filled buffer of at least spi_padding_bytes size.
  *			The dummy bytes that will be sent out between the
- *			address and data of a SPI read operation.
+ *			address and data of a SPI read operation. Not
+ *			allocated when reads are done in a single transfer.
  */
 struct ocelot_ddata {
 	enum ocelot_chip chip;
@@ -47,6 +51,7 @@ struct ocelot_ddata {
 	unsigned int if_cfgstat;
 	u32 if_cfgstat_si;
 	int spi_padding_bytes;
+	bool single_xfer_read;
 	void *dummy_buf;
 };
 

-- 
2.52.0


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

* Re: [PATCH v2 4/5] mfd: ocelot: Add support for the LAN9645x switch family
  2026-12-04 12:02 ` [PATCH v2 4/5] mfd: ocelot: Add support for the " Jens Emil Schulz Østergaard
@ 2026-12-05 12:03   ` sashiko-bot
  0 siblings, 0 replies; 7+ messages in thread
From: sashiko-bot @ 2026-12-05 12:03 UTC (permalink / raw)
  To: Jens Emil Schulz Østergaard; +Cc: mfd, devicetree, robh, conor+dt, lee

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Low] mfd: ocelot: duplicate LAN9645x GCB regmap due to resource name
  mismatch
- [Low] mfd: ocelot: data race on spi_padding_bytes in
  ocelot_spi_probe()
--

commit 3668fbd43fcd3e9655859afe6d486c660c2336eb
Author: Jens Emil Schulz Østergaard <jensemil.schulzostergaard@microchip.com>

mfd: ocelot: Add support for the LAN9645x switch family

This commit adds MFD and SPI regmap support for the LAN9645x switch family,
including chip reset handling, SPI padding byte calculation around reset,
and child MFD cell definitions.

> diff --git a/drivers/mfd/ocelot-spi.c b/drivers/mfd/ocelot-spi.c
> index b02f8a5eaab92..eb040be912048 100644
> --- a/drivers/mfd/ocelot-spi.c
> +++ b/drivers/mfd/ocelot-spi.c

[ ... ]

> @@ -50,6 +57,10 @@ static const struct resource vsc7512_gcb_resource =
>  			     VSC7512_CHIP_REGS_RES_SIZE,
>  			     "devcpu_gcb_chip_regs");
>  
> +static const struct resource lan9645x_gcb_resource =
> +	DEFINE_RES_REG_NAMED(LAN9645X_GCB_RES_START, LAN9645X_GCB_RES_SIZE,
> +			     "devcpu_gcb");
> +
>  static int vsc7512_spi_padding_bytes(u32 max_speed_hz)
>  {
>  	if (max_speed_hz <= 500000)

[Severity: Low]
Does naming lan9645x_gcb_resource "devcpu_gcb" cause a duplicate regmap
for the GCB block?

lan9645x_switch_resources defines the same GCB range under the name "gcb".
Because ocelot_core_try_add_regmap() deduplicates by resource name via
dev_get_regmap(dev, res->name), every LAN9645x probe creates a second
regmap and debugfs entry for the same registers.

Naming lan9645x_gcb_resource "gcb" would let ocelot_core_try_add_regmap()
reuse the regmap created in ocelot_spi_probe().

[ ... ]

> @@ -266,6 +306,8 @@ static int ocelot_spi_probe(struct spi_device *spi)
>  	 * This must be done before calling init, and after a chip reset is
>  	 * performed.
>  	 */
> +	ddata->spi_padding_bytes = reset_padding ?: padding;
> +
>  	err = ocelot_spi_initialize(dev);
>  	if (err)
>  		return dev_err_probe(dev, err, "Error initializing SPI bus\n");
> @@ -278,6 +320,8 @@ static int ocelot_spi_probe(struct spi_device *spi)
>  	 * A chip reset will clear the SPI configuration, so it needs to be done
>  	 * again before we can access any registers.
>  	 */
> +	ddata->spi_padding_bytes = padding;
> +
>  	err = ocelot_spi_initialize(dev);
>  	if (err)
>  		return dev_err_probe(dev, err, "Error initializing SPI bus after reset\n");

[Severity: Low]
Can updating ddata->spi_padding_bytes here race with concurrent regmap
reads from debugfs?

ocelot_spi_init_regmap() exposes the regmap's debugfs registers file via
devm_regmap_init() before probe finishes.  A concurrent root read of that
file calls ocelot_spi_regmap_bus_read() under map->mutex, while probe
writes ddata->spi_padding_bytes without that lock or WRITE_ONCE():

CPU0                             CPU1
ocelot_spi_probe()
  ocelot_spi_init_regmap()
    devm_regmap_init()
      regmap_debugfs_init()
                                 regmap_read_debugfs()
                                   regmap_read()
                                     ocelot_spi_regmap_bus_read()
  ddata->spi_padding_bytes = ...       if (ddata->spi_padding_bytes)
                                         <-- data race

This causes a data race on ddata->spi_padding_bytes and transiently
mismatched SPI padding for the debugfs read, especially while
ocelot_chip_reset() sleeps.

Initializing spi_padding_bytes before ocelot_spi_init_regmap() and using
WRITE_ONCE()/READ_ONCE() or the regmap lock avoids the race.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261204-mfd-ocelot-add-lan9645x-support-v2-0-d0b811aebfbf@microchip.com?part=4

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

end of thread, other threads:[~2026-12-05 12:03 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-04 12:02 [PATCH v2 0/5] mfd: ocelot: Support the LAN9645x switch family Jens Emil Schulz Østergaard
2026-12-04 12:02 ` [PATCH v2 1/5] mfd: ocelot: Define the VSC7512 cells with the MFD_CELL_* macros Jens Emil Schulz Østergaard
2026-12-04 12:02 ` [PATCH v2 2/5] mfd: ocelot: Select the chip through match data Jens Emil Schulz Østergaard
2026-12-04 12:02 ` [PATCH v2 3/5] dt-bindings: mfd: Add the Microchip LAN9645x switch family Jens Emil Schulz Østergaard
2026-12-04 12:02 ` [PATCH v2 4/5] mfd: ocelot: Add support for the " Jens Emil Schulz Østergaard
2026-12-05 12:03   ` sashiko-bot
2026-12-04 12:02 ` [PATCH v2 5/5] mfd: ocelot: Read LAN9645x registers in a single SPI transfer Jens Emil Schulz Østergaard

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.