Netdev List
 help / color / mirror / Atom feed
* [PATCH 0/4] mfd: ocelot: Support the LAN9645x switch family
@ 2026-11-23 13:25 Jens Emil Schulz Østergaard
  2026-11-23 13:25 ` [PATCH 1/4] mfd: ocelot: Select the chip through match data Jens Emil Schulz Østergaard
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: Jens Emil Schulz Østergaard @ 2026-11-23 13:25 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 moves the VSC7512 specific SPI interface, reset and child device
setup into match data and per chip tables.

Patch 2 adds a binding for the LAN9645x family.

Patch 3 adds the LAN9645x support.

Patch 4 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 2 references the switch binding
net/dsa/microchip,lan96455s-switch.yaml, and patch 2 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 2 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>
---
Jens Emil Schulz Østergaard (4):
      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                          | 263 ++++++++++++++++++++-
 drivers/mfd/ocelot-spi.c                           | 242 ++++++++++++++++---
 drivers/mfd/ocelot.h                               |  25 +-
 6 files changed, 617 insertions(+), 48 deletions(-)
---
base-commit: eb6d6c80d35449c27471b1874f13066c09a8964d
change-id: 20261118-mfd-ocelot-add-lan9645x-support-9ac4042ba475

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


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

* [PATCH 1/4] mfd: ocelot: Select the chip through match data
  2026-11-23 13:25 [PATCH 0/4] mfd: ocelot: Support the LAN9645x switch family Jens Emil Schulz Østergaard
@ 2026-11-23 13:25 ` Jens Emil Schulz Østergaard
  2026-12-02 12:34   ` Lee Jones
  2026-11-23 13:25 ` [PATCH 2/4] dt-bindings: mfd: Add the Microchip LAN9645x switch family Jens Emil Schulz Østergaard
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 8+ messages in thread
From: Jens Emil Schulz Østergaard @ 2026-11-23 13:25 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. Describe the serial interface configuration
target, its registers, the IF_CFGSTAT readback check and the padding
byte calculation in SPI match data, and select the soft reset register
and the child devices in the core by the chip it names. This prepares
for adding the LAN9645x switch family.

The VSC7512 soft reset defines get a VSC7512 prefix.

The probe now 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>
---
 drivers/mfd/ocelot-core.c | 48 +++++++++++++++++++++++------
 drivers/mfd/ocelot-spi.c  | 77 +++++++++++++++++++++++++++++++++--------------
 drivers/mfd/ocelot.h      |  6 ++++
 3 files changed, 100 insertions(+), 31 deletions(-)

diff --git a/drivers/mfd/ocelot-core.c b/drivers/mfd/ocelot-core.c
index 41aff2708854..2f53122fb964 100644
--- a/drivers/mfd/ocelot-core.c
+++ b/drivers/mfd/ocelot-core.c
@@ -28,9 +28,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,11 +84,23 @@
 #define VSC7512_GCB_RST_SLEEP_US	100
 #define VSC7512_GCB_RST_TIMEOUT_US	100000
 
+struct ocelot_soft_rst {
+	unsigned int reg;
+	u32 mask;
+};
+
+static const struct ocelot_soft_rst ocelot_soft_rst[] = {
+	[OCELOT_CHIP_VSC7512] = {
+		.reg = VSC7512_GCB_SOFT_RST,
+		.mask = VSC7512_SOFT_CHIP_RST,
+	},
+};
+
 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);
+	err = regmap_read(ddata->gcb_regmap, ocelot_soft_rst[ddata->chip].reg, &val);
 	if (err)
 		return err;
 
@@ -98,15 +110,18 @@ static int ocelot_gcb_chip_rst_status(struct ocelot_ddata *ddata)
 int ocelot_chip_reset(struct device *dev)
 {
 	struct ocelot_ddata *ddata = dev_get_drvdata(dev);
+	const struct ocelot_soft_rst *rst;
 	int ret, val;
 
+	rst = &ocelot_soft_rst[ddata->chip];
+
 	/*
 	 * Reset the entire chip here to put it into a completely known state.
 	 * Other drivers may want to reset their own subsystems. The register
 	 * 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, rst->reg, rst->mask);
 	if (ret)
 		return ret;
 
@@ -197,6 +212,18 @@ static const struct mfd_cell vsc7512_devs[] = {
 	},
 };
 
+struct ocelot_cells {
+	const struct mfd_cell *cells;
+	unsigned int num_cells;
+};
+
+static const struct ocelot_cells ocelot_cells[] = {
+	[OCELOT_CHIP_VSC7512] = {
+		.cells = vsc7512_devs,
+		.num_cells = ARRAY_SIZE(vsc7512_devs),
+	},
+};
+
 static void ocelot_core_try_add_regmap(struct device *dev,
 				       const struct resource *res)
 {
@@ -217,14 +244,17 @@ 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 ocelot_cells *c;
+	int i;
 
-	ndevs = ARRAY_SIZE(vsc7512_devs);
+	c = &ocelot_cells[ddata->chip];
 
-	for (i = 0; i < ndevs; i++)
-		ocelot_core_try_add_regmaps(dev, &vsc7512_devs[i]);
+	for (i = 0; i < c->num_cells; i++)
+		ocelot_core_try_add_regmaps(dev, &c->cells[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, c->cells, c->num_cells,
+				    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..e803d0363e62 100644
--- a/drivers/mfd/ocelot-spi.c
+++ b/drivers/mfd/ocelot-spi.c
@@ -50,7 +50,42 @@ static const struct resource vsc7512_gcb_resource =
 			     VSC7512_CHIP_REGS_RES_SIZE,
 			     "devcpu_gcb_chip_regs");
 
-static int ocelot_spi_initialize(struct device *dev)
+struct ocelot_spi_data {
+	enum ocelot_chip chip;
+	const struct resource *cpuorg_res;
+	unsigned int if_ctrl;
+	unsigned int if_cfgstat;
+	u32 if_cfgstat_si;
+	const struct resource *gcb_res;
+	int (*padding_bytes)(u32 max_speed_hz);
+};
+
+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 const struct ocelot_spi_data vsc7512_spi_data = {
+	.chip = OCELOT_CHIP_VSC7512,
+	.cpuorg_res = &vsc7512_dev_cpuorg_resource,
+	.if_ctrl = REG_DEV_CPUORG_IF_CTRL,
+	.if_cfgstat = REG_DEV_CPUORG_IF_CFGSTAT,
+	.if_cfgstat_si = CFGSTAT_IF_NUM_SI,
+	.gcb_res = &vsc7512_gcb_resource,
+	.padding_bytes = vsc7512_spi_padding_bytes,
+};
+
+static int ocelot_spi_initialize(struct device *dev,
+				 const struct ocelot_spi_data *data)
 {
 	struct ocelot_ddata *ddata = dev_get_drvdata(dev);
 	u32 val, check;
@@ -80,7 +115,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, data->if_ctrl, val);
 	if (err)
 		return err;
 
@@ -90,7 +125,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, data->if_cfgstat, val);
 	if (err)
 		return err;
 
@@ -109,9 +144,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 | data->if_cfgstat_si;
 
-	err = regmap_read(ddata->cpuorg_regmap, REG_DEV_CPUORG_IF_CFGSTAT, &val);
+	err = regmap_read(ddata->cpuorg_regmap, data->if_cfgstat, &val);
 	if (err)
 		return err;
 
@@ -196,28 +231,26 @@ EXPORT_SYMBOL_NS(ocelot_spi_init_regmap, "MFD_OCELOT_SPI");
 
 static int ocelot_spi_probe(struct spi_device *spi)
 {
+	const struct ocelot_spi_data *data;
 	struct device *dev = &spi->dev;
 	struct ocelot_ddata *ddata;
 	struct regmap *r;
 	int err;
 
+	data = spi_get_device_match_data(spi);
+	if (!data)
+		return -ENODEV;
+
 	ddata = devm_kzalloc_obj(dev, *ddata);
 	if (!ddata)
 		return -ENOMEM;
 
+	ddata->chip = data->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;
-
+	ddata->spi_padding_bytes = data->padding_bytes(spi->max_speed_hz);
+	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 +262,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, data->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, data->gcb_res);
 	if (IS_ERR(r))
 		return PTR_ERR(r);
 
@@ -246,7 +279,7 @@ static int ocelot_spi_probe(struct spi_device *spi)
 	 * This must be done before calling init, and after a chip reset is
 	 * performed.
 	 */
-	err = ocelot_spi_initialize(dev);
+	err = ocelot_spi_initialize(dev, data);
 	if (err)
 		return dev_err_probe(dev, err, "Error initializing SPI bus\n");
 
@@ -258,7 +291,7 @@ 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.
 	 */
-	err = ocelot_spi_initialize(dev);
+	err = ocelot_spi_initialize(dev, data);
 	if (err)
 		return dev_err_probe(dev, err, "Error initializing SPI bus after reset\n");
 
@@ -270,13 +303,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 = (kernel_ulong_t)&vsc7512_spi_data },
 	{ }
 };
 MODULE_DEVICE_TABLE(spi, ocelot_spi_ids);
 
 static const struct of_device_id ocelot_spi_of_match[] = {
-	{ .compatible = "mscc,vsc7512" },
+	{ .compatible = "mscc,vsc7512", .data = &vsc7512_spi_data },
 	{ }
 };
 MODULE_DEVICE_TABLE(of, ocelot_spi_of_match);
diff --git a/drivers/mfd/ocelot.h b/drivers/mfd/ocelot.h
index b8bc2f1486e2..92b5b893ff9b 100644
--- a/drivers/mfd/ocelot.h
+++ b/drivers/mfd/ocelot.h
@@ -10,8 +10,13 @@ struct device;
 struct regmap;
 struct resource;
 
+enum ocelot_chip {
+	OCELOT_CHIP_VSC7512,
+};
+
 /**
  * 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
@@ -24,6 +29,7 @@ struct resource;
  *			data of a SPI read operation.
  */
 struct ocelot_ddata {
+	enum ocelot_chip chip;
 	struct regmap *gcb_regmap;
 	struct regmap *cpuorg_regmap;
 	int spi_padding_bytes;

-- 
2.52.0


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

* [PATCH 2/4] dt-bindings: mfd: Add the Microchip LAN9645x switch family
  2026-11-23 13:25 [PATCH 0/4] mfd: ocelot: Support the LAN9645x switch family Jens Emil Schulz Østergaard
  2026-11-23 13:25 ` [PATCH 1/4] mfd: ocelot: Select the chip through match data Jens Emil Schulz Østergaard
@ 2026-11-23 13:25 ` Jens Emil Schulz Østergaard
  2026-11-23 13:25 ` [PATCH 3/4] mfd: ocelot: Add support for the " Jens Emil Schulz Østergaard
  2026-11-23 13:25 ` [PATCH 4/4] mfd: ocelot: Read LAN9645x registers in a single SPI transfer Jens Emil Schulz Østergaard
  3 siblings, 0 replies; 8+ messages in thread
From: Jens Emil Schulz Østergaard @ 2026-11-23 13:25 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 97308edec53d..b254f8c92b0d 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -18331,6 +18331,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] 8+ messages in thread

* [PATCH 3/4] mfd: ocelot: Add support for the LAN9645x switch family
  2026-11-23 13:25 [PATCH 0/4] mfd: ocelot: Support the LAN9645x switch family Jens Emil Schulz Østergaard
  2026-11-23 13:25 ` [PATCH 1/4] mfd: ocelot: Select the chip through match data Jens Emil Schulz Østergaard
  2026-11-23 13:25 ` [PATCH 2/4] dt-bindings: mfd: Add the Microchip LAN9645x switch family Jens Emil Schulz Østergaard
@ 2026-11-23 13:25 ` Jens Emil Schulz Østergaard
  2026-12-02 13:28   ` Lee Jones
  2026-11-23 13:25 ` [PATCH 4/4] mfd: ocelot: Read LAN9645x registers in a single SPI transfer Jens Emil Schulz Østergaard
  3 siblings, 1 reply; 8+ messages in thread
From: Jens Emil Schulz Østergaard @ 2026-11-23 13:25 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 General Configuration Block also holds groups for several
peripherals such as the GPIO, SGPIO and MIIM registers, and also the
FEAT_DISABLE register used by the switch driver. Let the core pass
regmap access tables per resource name, and make the switch gcb regmap
cover the whole target, so the switch driver keeps its offsets relative
to the target, but readable only at FEAT_DISABLE.

The chip top target holds the CuPHY configuration, the GPIO pad
configuration, the strapping and the PLL and sensor registers, while
the MIIM cell owns CUPHY_COMMON_CFG. Restrict the switch chip_top regmap
in the same way to the per port CuPHY status, configuration and LED
registers and to the strapping register.

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>
---
 drivers/mfd/Kconfig       |   2 +-
 drivers/mfd/ocelot-core.c | 217 +++++++++++++++++++++++++++++++++++++++++++++-
 drivers/mfd/ocelot-spi.c  |  85 +++++++++++++++---
 drivers/mfd/ocelot.h      |  18 ++--
 4 files changed, 300 insertions(+), 22 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 2f53122fb964..e95ac56df37a 100644
--- a/drivers/mfd/ocelot-core.c
+++ b/drivers/mfd/ocelot-core.c
@@ -22,6 +22,7 @@
 #include <linux/mfd/ocelot.h>
 #include <linux/module.h>
 #include <linux/regmap.h>
+#include <linux/string.h>
 #include <linux/types.h>
 
 #include <soc/mscc/ocelot.h>
@@ -81,6 +82,74 @@
 #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_GCB_FEAT_DISABLE	0x0014
+
+#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_CUPHY_PORT_STAT	0x000c
+#define LAN9645X_CHIP_TOP_CUPHY_LED_CFG(n)	(0x0034 + 4 * (n))
+#define LAN9645X_CHIP_TOP_STRAPPING		0x0118
+
+#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
 
@@ -90,6 +159,10 @@ struct ocelot_soft_rst {
 };
 
 static const struct ocelot_soft_rst ocelot_soft_rst[] = {
+	[OCELOT_CHIP_LAN9645X] = {
+		.reg = LAN9645X_GCB_SOFT_RST,
+		.mask = LAN9645X_SOFT_SWC_RST,
+	},
 	[OCELOT_CHIP_VSC7512] = {
 		.reg = VSC7512_GCB_SOFT_RST,
 		.mask = VSC7512_SOFT_CHIP_RST,
@@ -212,12 +285,136 @@ static const struct mfd_cell vsc7512_devs[] = {
 	},
 };
 
+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[] = {
+	{
+		.name = "lan9645x-pinctrl",
+		.of_compatible = "microchip,lan96455f-pinctrl",
+		.num_resources = ARRAY_SIZE(lan9645x_pinctrl_resources),
+		.resources = lan9645x_pinctrl_resources,
+	}, {
+		.name = "lan9645x-miim0",
+		.of_compatible = "microchip,lan966x-miim",
+		.of_reg = LAN9645X_MIIM0_RES_START,
+		.use_of_reg = true,
+		.num_resources = ARRAY_SIZE(lan9645x_miim0_resources),
+		.resources = lan9645x_miim0_resources,
+	}, {
+		.name = "lan9645x-miim1",
+		.of_compatible = "microchip,lan966x-miim",
+		.of_reg = LAN9645X_MIIM1_RES_START,
+		.use_of_reg = true,
+		.num_resources = ARRAY_SIZE(lan9645x_miim1_resources),
+		.resources = lan9645x_miim1_resources,
+	}, {
+		.name = "lan9645x-switch",
+		.of_compatible = "microchip,lan96455s-switch",
+		.num_resources = ARRAY_SIZE(lan9645x_switch_resources),
+		.resources = lan9645x_switch_resources,
+	},
+};
+
+static const struct regmap_range lan9645x_gcb_rd_ranges[] = {
+	regmap_reg_range(LAN9645X_GCB_FEAT_DISABLE, LAN9645X_GCB_FEAT_DISABLE),
+};
+
+static const struct regmap_access_table lan9645x_gcb_rd_table = {
+	.yes_ranges = lan9645x_gcb_rd_ranges,
+	.n_yes_ranges = ARRAY_SIZE(lan9645x_gcb_rd_ranges),
+};
+
+static const struct regmap_range lan9645x_gcb_wr_no_ranges[] = {
+	regmap_reg_range(0, LAN9645X_GCB_RES_SIZE - 1),
+};
+
+static const struct regmap_access_table lan9645x_gcb_wr_table = {
+	.no_ranges = lan9645x_gcb_wr_no_ranges,
+	.n_no_ranges = ARRAY_SIZE(lan9645x_gcb_wr_no_ranges),
+};
+
+static const struct regmap_range lan9645x_chip_top_ranges[] = {
+	regmap_reg_range(LAN9645X_CHIP_TOP_CUPHY_PORT_STAT,
+			 LAN9645X_CHIP_TOP_CUPHY_LED_CFG(4)),
+	regmap_reg_range(LAN9645X_CHIP_TOP_STRAPPING,
+			 LAN9645X_CHIP_TOP_STRAPPING),
+};
+
+static const struct regmap_access_table lan9645x_chip_top_table = {
+	.yes_ranges = lan9645x_chip_top_ranges,
+	.n_yes_ranges = ARRAY_SIZE(lan9645x_chip_top_ranges),
+};
+
+struct ocelot_regmap_access {
+	const char *name;
+	const struct regmap_access_table *rd_table;
+	const struct regmap_access_table *wr_table;
+};
+
+static const struct ocelot_regmap_access lan9645x_regmap_access[] = {
+	{
+		.name = "gcb",
+		.rd_table = &lan9645x_gcb_rd_table,
+		.wr_table = &lan9645x_gcb_wr_table,
+	}, {
+		.name = "chip_top",
+		.rd_table = &lan9645x_chip_top_table,
+		.wr_table = &lan9645x_chip_top_table,
+	},
+};
+
 struct ocelot_cells {
 	const struct mfd_cell *cells;
 	unsigned int num_cells;
+	const struct ocelot_regmap_access *access;
+	unsigned int num_access;
 };
 
 static const struct ocelot_cells ocelot_cells[] = {
+	[OCELOT_CHIP_LAN9645X] = {
+		.cells = lan9645x_devs,
+		.num_cells = ARRAY_SIZE(lan9645x_devs),
+		.access = lan9645x_regmap_access,
+		.num_access = ARRAY_SIZE(lan9645x_regmap_access),
+	},
 	[OCELOT_CHIP_VSC7512] = {
 		.cells = vsc7512_devs,
 		.num_cells = ARRAY_SIZE(vsc7512_devs),
@@ -225,21 +422,35 @@ static const struct ocelot_cells ocelot_cells[] = {
 };
 
 static void ocelot_core_try_add_regmap(struct device *dev,
+				       const struct ocelot_cells *c,
 				       const struct resource *res)
 {
+	const struct regmap_access_table *rd_table = NULL;
+	const struct regmap_access_table *wr_table = NULL;
+	int i;
+
 	if (dev_get_regmap(dev, res->name))
 		return;
 
-	ocelot_spi_init_regmap(dev, res);
+	for (i = 0; i < c->num_access; i++) {
+		if (!strcmp(c->access[i].name, res->name)) {
+			rd_table = c->access[i].rd_table;
+			wr_table = c->access[i].wr_table;
+			break;
+		}
+	}
+
+	ocelot_spi_init_regmap(dev, res, rd_table, wr_table);
 }
 
 static void ocelot_core_try_add_regmaps(struct device *dev,
+					const struct ocelot_cells *c,
 					const struct mfd_cell *cell)
 {
 	int i;
 
 	for (i = 0; i < cell->num_resources; i++)
-		ocelot_core_try_add_regmap(dev, &cell->resources[i]);
+		ocelot_core_try_add_regmap(dev, c, &cell->resources[i]);
 }
 
 int ocelot_core_init(struct device *dev)
@@ -251,7 +462,7 @@ int ocelot_core_init(struct device *dev)
 	c = &ocelot_cells[ddata->chip];
 
 	for (i = 0; i < c->num_cells; i++)
-		ocelot_core_try_add_regmaps(dev, &c->cells[i]);
+		ocelot_core_try_add_regmaps(dev, c, &c->cells[i]);
 
 	return devm_mfd_add_devices(dev, PLATFORM_DEVID_AUTO, c->cells, c->num_cells,
 				    NULL, 0, NULL);
diff --git a/drivers/mfd/ocelot-spi.c b/drivers/mfd/ocelot-spi.c
index e803d0363e62..6d405627136d 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");
+
 struct ocelot_spi_data {
 	enum ocelot_chip chip;
 	const struct resource *cpuorg_res;
@@ -57,6 +68,7 @@ struct ocelot_spi_data {
 	unsigned int if_cfgstat;
 	u32 if_cfgstat_si;
 	const struct resource *gcb_res;
+	int reset_padding_bytes;
 	int (*padding_bytes)(u32 max_speed_hz);
 };
 
@@ -74,6 +86,27 @@ 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)
+{
+	u32 khz = max_speed_hz / HZ_PER_KHZ;
+
+	/*
+	 * 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(khz * LAN9645X_REG_ACCESS_TIME_US + 1500, 8000);
+}
+
+static const struct ocelot_spi_data lan9645x_spi_data = {
+	.chip = OCELOT_CHIP_LAN9645X,
+	.cpuorg_res = &lan9645x_gcb_resource,
+	.if_ctrl = LAN9645X_IF_CTRL,
+	.if_cfgstat = LAN9645X_IF_CFGSTAT,
+	.gcb_res = &lan9645x_gcb_resource,
+	.reset_padding_bytes = LAN9645X_RESET_PADDING_BYTES,
+	.padding_bytes = lan9645x_spi_padding_bytes,
+};
+
 static const struct ocelot_spi_data vsc7512_spi_data = {
 	.chip = OCELOT_CHIP_VSC7512,
 	.cpuorg_res = &vsc7512_dev_cpuorg_resource,
@@ -142,7 +175,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 | data->if_cfgstat_si;
 
@@ -215,7 +249,10 @@ static const struct regmap_bus ocelot_spi_regmap_bus = {
 	.read = ocelot_spi_regmap_bus_read,
 };
 
-struct regmap *ocelot_spi_init_regmap(struct device *dev, const struct resource *res)
+struct regmap *ocelot_spi_init_regmap(struct device *dev,
+				      const struct resource *res,
+				      const struct regmap_access_table *rd_table,
+				      const struct regmap_access_table *wr_table)
 {
 	struct regmap_config regmap_config;
 
@@ -224,6 +261,8 @@ struct regmap *ocelot_spi_init_regmap(struct device *dev, const struct resource
 	regmap_config.name = res->name;
 	regmap_config.max_register = resource_size(res) - 1;
 	regmap_config.reg_base = res->start;
+	regmap_config.rd_table = rd_table;
+	regmap_config.wr_table = wr_table;
 
 	return devm_regmap_init(dev, &ocelot_spi_regmap_bus, dev, &regmap_config);
 }
@@ -234,6 +273,7 @@ static int ocelot_spi_probe(struct spi_device *spi)
 	const struct ocelot_spi_data *data;
 	struct device *dev = &spi->dev;
 	struct ocelot_ddata *ddata;
+	int padding, dummy_len;
 	struct regmap *r;
 	int err;
 
@@ -249,9 +289,15 @@ static int ocelot_spi_probe(struct spi_device *spi)
 
 	spi_set_drvdata(spi, ddata);
 
-	ddata->spi_padding_bytes = data->padding_bytes(spi->max_speed_hz);
-	if (ddata->spi_padding_bytes) {
-		ddata->dummy_buf = devm_kzalloc(dev, ddata->spi_padding_bytes, GFP_KERNEL);
+	padding = data->padding_bytes(spi->max_speed_hz);
+	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, data->reset_padding_bytes);
+	if (dummy_len) {
+		ddata->dummy_buf = devm_kzalloc(dev, dummy_len, GFP_KERNEL);
 		if (!ddata->dummy_buf)
 			return -ENOMEM;
 	}
@@ -262,15 +308,17 @@ 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, data->cpuorg_res);
+	r = ocelot_spi_init_regmap(dev, data->cpuorg_res, NULL, NULL);
 	if (IS_ERR(r))
 		return PTR_ERR(r);
 
 	ddata->cpuorg_regmap = r;
 
-	r = ocelot_spi_init_regmap(dev, data->gcb_res);
-	if (IS_ERR(r))
-		return PTR_ERR(r);
+	if (data->gcb_res != data->cpuorg_res) {
+		r = ocelot_spi_init_regmap(dev, data->gcb_res, NULL, NULL);
+		if (IS_ERR(r))
+			return PTR_ERR(r);
+	}
 
 	ddata->gcb_regmap = r;
 
@@ -279,6 +327,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 = data->reset_padding_bytes ?: padding;
+
 	err = ocelot_spi_initialize(dev, data);
 	if (err)
 		return dev_err_probe(dev, err, "Error initializing SPI bus\n");
@@ -291,6 +341,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, data);
 	if (err)
 		return dev_err_probe(dev, err, "Error initializing SPI bus after reset\n");
@@ -303,12 +355,19 @@ static int ocelot_spi_probe(struct spi_device *spi)
 }
 
 static const struct spi_device_id ocelot_spi_ids[] = {
+	{ .name = "lan96455f", .driver_data = (kernel_ulong_t)&lan9645x_spi_data },
+	{ .name = "lan96455s", .driver_data = (kernel_ulong_t)&lan9645x_spi_data },
+	{ .name = "lan96457f", .driver_data = (kernel_ulong_t)&lan9645x_spi_data },
+	{ .name = "lan96457s", .driver_data = (kernel_ulong_t)&lan9645x_spi_data },
+	{ .name = "lan96459f", .driver_data = (kernel_ulong_t)&lan9645x_spi_data },
+	{ .name = "lan96459s", .driver_data = (kernel_ulong_t)&lan9645x_spi_data },
 	{ .name = "vsc7512", .driver_data = (kernel_ulong_t)&vsc7512_spi_data },
 	{ }
 };
 MODULE_DEVICE_TABLE(spi, ocelot_spi_ids);
 
 static const struct of_device_id ocelot_spi_of_match[] = {
+	{ .compatible = "microchip,lan96455s", .data = &lan9645x_spi_data },
 	{ .compatible = "mscc,vsc7512", .data = &vsc7512_spi_data },
 	{ }
 };
diff --git a/drivers/mfd/ocelot.h b/drivers/mfd/ocelot.h
index 92b5b893ff9b..fa02590a5026 100644
--- a/drivers/mfd/ocelot.h
+++ b/drivers/mfd/ocelot.h
@@ -8,9 +8,14 @@
 
 struct device;
 struct regmap;
+struct regmap_access_table;
 struct resource;
 
+#define LAN9645X_GCB_RES_START		0x00004000
+#define LAN9645X_GCB_RES_SIZE		0x00000244
+
 enum ocelot_chip {
+	OCELOT_CHIP_LAN9645X,
 	OCELOT_CHIP_VSC7512,
 };
 
@@ -23,10 +28,11 @@ enum ocelot_chip {
  *			like SPI bus configuration.
  * @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;
@@ -41,7 +47,9 @@ int ocelot_core_init(struct device *dev);
 
 /* SPI-specific routines that won't be necessary for other interfaces */
 struct regmap *ocelot_spi_init_regmap(struct device *dev,
-				      const struct resource *res);
+				      const struct resource *res,
+				      const struct regmap_access_table *rd_table,
+				      const struct regmap_access_table *wr_table);
 
 #define OCELOT_SPI_BYTE_ORDER_LE 0x00000000
 #define OCELOT_SPI_BYTE_ORDER_BE 0x81818181

-- 
2.52.0


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

* [PATCH 4/4] mfd: ocelot: Read LAN9645x registers in a single SPI transfer
  2026-11-23 13:25 [PATCH 0/4] mfd: ocelot: Support the LAN9645x switch family Jens Emil Schulz Østergaard
                   ` (2 preceding siblings ...)
  2026-11-23 13:25 ` [PATCH 3/4] mfd: ocelot: Add support for the " Jens Emil Schulz Østergaard
@ 2026-11-23 13:25 ` Jens Emil Schulz Østergaard
  2026-12-02 13:35   ` Lee Jones
  3 siblings, 1 reply; 8+ messages in thread
From: Jens Emil Schulz Østergaard @ 2026-11-23 13:25 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 transfer
buffer is allocated per regmap, so the regmap lock serializes its use.

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>
---
 drivers/mfd/ocelot-spi.c | 92 ++++++++++++++++++++++++++++++++++++++++++++++--
 drivers/mfd/ocelot.h     |  3 +-
 2 files changed, 92 insertions(+), 3 deletions(-)

diff --git a/drivers/mfd/ocelot-spi.c b/drivers/mfd/ocelot-spi.c
index 6d405627136d..4f2ef847c909 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,
@@ -70,6 +76,12 @@ struct ocelot_spi_data {
 	const struct resource *gcb_res;
 	int reset_padding_bytes;
 	int (*padding_bytes)(u32 max_speed_hz);
+	bool single_xfer_read;
+};
+
+struct ocelot_spi_regmap_ctx {
+	struct device *dev;
+	u8 buf[OCELOT_SPI_XFER_BUF_SIZE] __aligned(ARCH_DMA_MINALIGN);
 };
 
 static int vsc7512_spi_padding_bytes(u32 max_speed_hz)
@@ -105,6 +117,7 @@ static const struct ocelot_spi_data lan9645x_spi_data = {
 	.gcb_res = &lan9645x_gcb_resource,
 	.reset_padding_bytes = LAN9645X_RESET_PADDING_BYTES,
 	.padding_bytes = lan9645x_spi_padding_bytes,
+	.single_xfer_read = true,
 };
 
 static const struct ocelot_spi_data vsc7512_spi_data = {
@@ -249,12 +262,78 @@ 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 spi_transfer xfer = {};
+	struct ocelot_ddata *ddata;
+	const u8 *regu8 = reg;
+	u8 *buf = ctx->buf;
+	u8 *valu8 = val;
+	size_t off;
+	int err;
+
+	ddata = dev_get_drvdata(ctx->dev);
+
+	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;
+
+	buf[0] = regu8[0];
+	buf[1] = regu8[1];
+	buf[2] = regu8[2];
+	memset(&buf[OCELOT_SPI_ADDR_SIZE], 0,
+	       ddata->spi_padding_bytes + OCELOT_SPI_VAL_SIZE);
+
+	xfer.tx_buf = buf;
+	xfer.rx_buf = buf;
+	xfer.len = off + OCELOT_SPI_VAL_SIZE;
+
+	err = spi_sync_transfer(to_spi_device(ctx->dev), &xfer, 1);
+	if (err)
+		return err;
+
+	valu8[0] = buf[off + 0];
+	valu8[1] = buf[off + 1];
+	valu8[2] = buf[off + 2];
+	valu8[3] = buf[off + 3];
+
+	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_single_xfer_read(struct spi_device *spi,
+					const struct ocelot_spi_data *data)
+{
+	return data->single_xfer_read &&
+	       !(spi->controller->flags & SPI_CONTROLLER_HALF_DUPLEX) &&
+	       !(spi->mode & SPI_3WIRE);
+}
+
 struct regmap *ocelot_spi_init_regmap(struct device *dev,
 				      const struct resource *res,
 				      const struct regmap_access_table *rd_table,
 				      const struct regmap_access_table *wr_table)
 {
+	struct spi_device *spi = to_spi_device(dev);
 	struct regmap_config regmap_config;
+	struct ocelot_spi_regmap_ctx *ctx;
 
 	memcpy(&regmap_config, &ocelot_spi_regmap_config, sizeof(regmap_config));
 
@@ -264,7 +343,16 @@ struct regmap *ocelot_spi_init_regmap(struct device *dev,
 	regmap_config.rd_table = rd_table;
 	regmap_config.wr_table = wr_table;
 
-	return devm_regmap_init(dev, &ocelot_spi_regmap_bus, dev, &regmap_config);
+	if (!ocelot_spi_single_xfer_read(spi, spi_get_device_match_data(spi)))
+		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");
 
@@ -296,7 +384,7 @@ static int ocelot_spi_probe(struct spi_device *spi)
 				     spi->max_speed_hz, OCELOT_SPI_MAX_PADDING_BYTES);
 
 	dummy_len = max(padding, data->reset_padding_bytes);
-	if (dummy_len) {
+	if (!ocelot_spi_single_xfer_read(spi, data) && 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 fa02590a5026..5d0301f0b194 100644
--- a/drivers/mfd/ocelot.h
+++ b/drivers/mfd/ocelot.h
@@ -32,7 +32,8 @@ enum ocelot_chip {
  *			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.
+ *			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;

-- 
2.52.0


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

* Re: [PATCH 1/4] mfd: ocelot: Select the chip through match data
  2026-11-23 13:25 ` [PATCH 1/4] mfd: ocelot: Select the chip through match data Jens Emil Schulz Østergaard
@ 2026-12-02 12:34   ` Lee Jones
  0 siblings, 0 replies; 8+ messages in thread
From: Lee Jones @ 2026-12-02 12:34 UTC (permalink / raw)
  To: Jens Emil Schulz Østergaard
  Cc: Colin Foster, UNGLinuxDriver, Rob Herring, Krzysztof Kozlowski,
	Conor Dooley, Richard Cochran, mfd, linux-kernel, netdev,
	devicetree

On Mon, 23 Nov 2026, Jens Emil Schulz Østergaard wrote:

> The SPI interface bootstrap, the chip reset and the child devices are
> hardcoded for the VSC7512. Describe the serial interface configuration
> target, its registers, the IF_CFGSTAT readback check and the padding
> byte calculation in SPI match data, and select the soft reset register
> and the child devices in the core by the chip it names. This prepares
> for adding the LAN9645x switch family.

I support the idea, just not the implementation.

> The VSC7512 soft reset defines get a VSC7512 prefix.
>
> The probe now 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>
> ---
>  drivers/mfd/ocelot-core.c | 48 +++++++++++++++++++++++------
>  drivers/mfd/ocelot-spi.c  | 77 +++++++++++++++++++++++++++++++++--------------
>  drivers/mfd/ocelot.h      |  6 ++++
>  3 files changed, 100 insertions(+), 31 deletions(-)
>
> diff --git a/drivers/mfd/ocelot-core.c b/drivers/mfd/ocelot-core.c
> index 41aff2708854..2f53122fb964 100644
> --- a/drivers/mfd/ocelot-core.c
> +++ b/drivers/mfd/ocelot-core.c
> @@ -28,9 +28,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,11 +84,23 @@
>  #define VSC7512_GCB_RST_SLEEP_US	100
>  #define VSC7512_GCB_RST_TIMEOUT_US	100000
>
> +struct ocelot_soft_rst {
> +	unsigned int reg;
> +	u32 mask;
> +};
> +
> +static const struct ocelot_soft_rst ocelot_soft_rst[] = {
> +	[OCELOT_CHIP_VSC7512] = {
> +		.reg = VSC7512_GCB_SOFT_RST,
> +		.mask = VSC7512_SOFT_CHIP_RST,
> +	},
> +};
> +
>  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);
> +	err = regmap_read(ddata->gcb_regmap, ocelot_soft_rst[ddata->chip].reg, &val);
>  	if (err)
>  		return err;
>
> @@ -98,15 +110,18 @@ static int ocelot_gcb_chip_rst_status(struct ocelot_ddata *ddata)
>  int ocelot_chip_reset(struct device *dev)
>  {
>  	struct ocelot_ddata *ddata = dev_get_drvdata(dev);
> +	const struct ocelot_soft_rst *rst;
>  	int ret, val;
>
> +	rst = &ocelot_soft_rst[ddata->chip];
> +
>  	/*
>  	 * Reset the entire chip here to put it into a completely known state.
>  	 * Other drivers may want to reset their own subsystems. The register
>  	 * 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, rst->reg, rst->mask);
>  	if (ret)
>  		return ret;
>
> @@ -197,6 +212,18 @@ static const struct mfd_cell vsc7512_devs[] = {
>  	},
>  };
>
> +struct ocelot_cells {
> +	const struct mfd_cell *cells;
> +	unsigned int num_cells;
> +};
> +
> +static const struct ocelot_cells ocelot_cells[] = {
> +	[OCELOT_CHIP_VSC7512] = {
> +		.cells = vsc7512_devs,
> +		.num_cells = ARRAY_SIZE(vsc7512_devs),
> +	},
> +};

Please select the 'mfd_cell' array and its size using a switch() statement on
'ddata->chip' inside ocelot_core_init() rather than introducing a wrapper struct
and an array of arrays.

Also, we already have helpers for you in:

  include/linux/mfd/core.h

>  static void ocelot_core_try_add_regmap(struct device *dev,
>  				       const struct resource *res)
>  {
> @@ -217,14 +244,17 @@ 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 ocelot_cells *c;
> +	int i;
>
> -	ndevs = ARRAY_SIZE(vsc7512_devs);
> +	c = &ocelot_cells[ddata->chip];
>
> -	for (i = 0; i < ndevs; i++)
> -		ocelot_core_try_add_regmaps(dev, &vsc7512_devs[i]);
> +	for (i = 0; i < c->num_cells; i++)

for (int i = 0; ...

> +		ocelot_core_try_add_regmaps(dev, &c->cells[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, c->cells, c->num_cells,
> +				    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..e803d0363e62 100644
> --- a/drivers/mfd/ocelot-spi.c
> +++ b/drivers/mfd/ocelot-spi.c
> @@ -50,7 +50,42 @@ static const struct resource vsc7512_gcb_resource =
>  			     VSC7512_CHIP_REGS_RES_SIZE,
>  			     "devcpu_gcb_chip_regs");
>
> -static int ocelot_spi_initialize(struct device *dev)
> +struct ocelot_spi_data {

May I suggest that we ditch this pdata strategy and assign these based
off of an integer that you pass through .data?

> +	enum ocelot_chip chip;
> +	const struct resource *cpuorg_res;
> +	unsigned int if_ctrl;
> +	unsigned int if_cfgstat;
> +	u32 if_cfgstat_si;
> +	const struct resource *gcb_res;
> +	int (*padding_bytes)(u32 max_speed_hz);

Function pointers at driver-level give me the ick.

Again, if there is no other way to do this other than in a function, you
can call it from within the correct case of the switch() suggested
above.  This way you can keep all of the chip specific logic together in
a coherent space.

> +};
> +
> +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 const struct ocelot_spi_data vsc7512_spi_data = {
> +	.chip = OCELOT_CHIP_VSC7512,
> +	.cpuorg_res = &vsc7512_dev_cpuorg_resource,
> +	.if_ctrl = REG_DEV_CPUORG_IF_CTRL,
> +	.if_cfgstat = REG_DEV_CPUORG_IF_CFGSTAT,
> +	.if_cfgstat_si = CFGSTAT_IF_NUM_SI,
> +	.gcb_res = &vsc7512_gcb_resource,
> +	.padding_bytes = vsc7512_spi_padding_bytes,
> +};
> +
> +static int ocelot_spi_initialize(struct device *dev,
> +				 const struct ocelot_spi_data *data)
>  {
>  	struct ocelot_ddata *ddata = dev_get_drvdata(dev);
>  	u32 val, check;
> @@ -80,7 +115,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, data->if_ctrl, val);
>  	if (err)
>  		return err;
>
> @@ -90,7 +125,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, data->if_cfgstat, val);
>  	if (err)
>  		return err;
>
> @@ -109,9 +144,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 | data->if_cfgstat_si;
>
> -	err = regmap_read(ddata->cpuorg_regmap, REG_DEV_CPUORG_IF_CFGSTAT, &val);
> +	err = regmap_read(ddata->cpuorg_regmap, data->if_cfgstat, &val);
>  	if (err)
>  		return err;
>
> @@ -196,28 +231,26 @@ EXPORT_SYMBOL_NS(ocelot_spi_init_regmap, "MFD_OCELOT_SPI");
>
>  static int ocelot_spi_probe(struct spi_device *spi)
>  {
> +	const struct ocelot_spi_data *data;
>  	struct device *dev = &spi->dev;
>  	struct ocelot_ddata *ddata;
>  	struct regmap *r;
>  	int err;
>
> +	data = spi_get_device_match_data(spi);
> +	if (!data)
> +		return -ENODEV;
> +
>  	ddata = devm_kzalloc_obj(dev, *ddata);
>  	if (!ddata)
>  		return -ENOMEM;
>
> +	ddata->chip = data->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;
> -
> +	ddata->spi_padding_bytes = data->padding_bytes(spi->max_speed_hz);
> +	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 +262,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, data->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, data->gcb_res);
>  	if (IS_ERR(r))
>  		return PTR_ERR(r);
>
> @@ -246,7 +279,7 @@ static int ocelot_spi_probe(struct spi_device *spi)
>  	 * This must be done before calling init, and after a chip reset is
>  	 * performed.
>  	 */
> -	err = ocelot_spi_initialize(dev);
> +	err = ocelot_spi_initialize(dev, data);
>  	if (err)
>  		return dev_err_probe(dev, err, "Error initializing SPI bus\n");
>
> @@ -258,7 +291,7 @@ 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.
>  	 */
> -	err = ocelot_spi_initialize(dev);
> +	err = ocelot_spi_initialize(dev, data);
>  	if (err)
>  		return dev_err_probe(dev, err, "Error initializing SPI bus after reset\n");
>
> @@ -270,13 +303,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 = (kernel_ulong_t)&vsc7512_spi_data },
>  	{ }
>  };
>  MODULE_DEVICE_TABLE(spi, ocelot_spi_ids);
>
>  static const struct of_device_id ocelot_spi_of_match[] = {
> -	{ .compatible = "mscc,vsc7512" },
> +	{ .compatible = "mscc,vsc7512", .data = &vsc7512_spi_data },
>  	{ }
>  };
>  MODULE_DEVICE_TABLE(of, ocelot_spi_of_match);
> diff --git a/drivers/mfd/ocelot.h b/drivers/mfd/ocelot.h
> index b8bc2f1486e2..92b5b893ff9b 100644
> --- a/drivers/mfd/ocelot.h
> +++ b/drivers/mfd/ocelot.h
> @@ -10,8 +10,13 @@ struct device;
>  struct regmap;
>  struct resource;
>
> +enum ocelot_chip {
> +	OCELOT_CHIP_VSC7512,
> +};
> +
>  /**
>   * 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
> @@ -24,6 +29,7 @@ struct resource;
>   *			data of a SPI read operation.
>   */
>  struct ocelot_ddata {
> +	enum ocelot_chip chip;
>  	struct regmap *gcb_regmap;
>  	struct regmap *cpuorg_regmap;
>  	int spi_padding_bytes;
>
> -- 
> 2.52.0
>

-- 
Lee Jones

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

* Re: [PATCH 3/4] mfd: ocelot: Add support for the LAN9645x switch family
  2026-11-23 13:25 ` [PATCH 3/4] mfd: ocelot: Add support for the " Jens Emil Schulz Østergaard
@ 2026-12-02 13:28   ` Lee Jones
  0 siblings, 0 replies; 8+ messages in thread
From: Lee Jones @ 2026-12-02 13:28 UTC (permalink / raw)
  To: Jens Emil Schulz Østergaard
  Cc: Colin Foster, UNGLinuxDriver, Rob Herring, Krzysztof Kozlowski,
	Conor Dooley, Richard Cochran, mfd, linux-kernel, netdev,
	devicetree

> 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 General Configuration Block also holds groups for several
> peripherals such as the GPIO, SGPIO and MIIM registers, and also the
> FEAT_DISABLE register used by the switch driver. Let the core pass
> regmap access tables per resource name, and make the switch gcb regmap
> cover the whole target, so the switch driver keeps its offsets relative
> to the target, but readable only at FEAT_DISABLE.
> 
> The chip top target holds the CuPHY configuration, the GPIO pad
> configuration, the strapping and the PLL and sensor registers, while
> the MIIM cell owns CUPHY_COMMON_CFG. Restrict the switch chip_top regmap
> in the same way to the per port CuPHY status, configuration and LED
> registers and to the strapping register.
> 
> 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>
> ---
>  drivers/mfd/Kconfig       |   2 +-
>  drivers/mfd/ocelot-core.c | 217 +++++++++++++++++++++++++++++++++++++++++++++-
>  drivers/mfd/ocelot-spi.c  |  85 +++++++++++++++---
>  drivers/mfd/ocelot.h      |  18 ++--
>  4 files changed, 300 insertions(+), 22 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 2f53122fb964..e95ac56df37a 100644
> --- a/drivers/mfd/ocelot-core.c
> +++ b/drivers/mfd/ocelot-core.c
> @@ -22,6 +22,7 @@
>  #include <linux/mfd/ocelot.h>
>  #include <linux/module.h>
>  #include <linux/regmap.h>
> +#include <linux/string.h>
>  #include <linux/types.h>
>  
>  #include <soc/mscc/ocelot.h>
> @@ -81,6 +82,74 @@
>  #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_GCB_FEAT_DISABLE	0x0014
> +
> +#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_CUPHY_PORT_STAT	0x000c
> +#define LAN9645X_CHIP_TOP_CUPHY_LED_CFG(n)	(0x0034 + 4 * (n))
> +#define LAN9645X_CHIP_TOP_STRAPPING		0x0118
> +
> +#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
>  
> @@ -90,6 +159,10 @@ struct ocelot_soft_rst {
>  };
>  
>  static const struct ocelot_soft_rst ocelot_soft_rst[] = {
> +	[OCELOT_CHIP_LAN9645X] = {
> +		.reg = LAN9645X_GCB_SOFT_RST,
> +		.mask = LAN9645X_SOFT_SWC_RST,
> +	},
>  	[OCELOT_CHIP_VSC7512] = {
>  		.reg = VSC7512_GCB_SOFT_RST,
>  		.mask = VSC7512_SOFT_CHIP_RST,
> @@ -212,12 +285,136 @@ static const struct mfd_cell vsc7512_devs[] = {
>  	},
>  };
>  
> +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[] = {
> +	{
> +		.name = "lan9645x-pinctrl",
> +		.of_compatible = "microchip,lan96455f-pinctrl",
> +		.num_resources = ARRAY_SIZE(lan9645x_pinctrl_resources),
> +		.resources = lan9645x_pinctrl_resources,
> +	}, {
> +		.name = "lan9645x-miim0",
> +		.of_compatible = "microchip,lan966x-miim",
> +		.of_reg = LAN9645X_MIIM0_RES_START,
> +		.use_of_reg = true,
> +		.num_resources = ARRAY_SIZE(lan9645x_miim0_resources),
> +		.resources = lan9645x_miim0_resources,
> +	}, {
> +		.name = "lan9645x-miim1",
> +		.of_compatible = "microchip,lan966x-miim",
> +		.of_reg = LAN9645X_MIIM1_RES_START,
> +		.use_of_reg = true,
> +		.num_resources = ARRAY_SIZE(lan9645x_miim1_resources),
> +		.resources = lan9645x_miim1_resources,
> +	}, {
> +		.name = "lan9645x-switch",
> +		.of_compatible = "microchip,lan96455s-switch",
> +		.num_resources = ARRAY_SIZE(lan9645x_switch_resources),
> +		.resources = lan9645x_switch_resources,
> +	},
> +};

MFD_CELL_*

> +static const struct regmap_range lan9645x_gcb_rd_ranges[] = {
> +	regmap_reg_range(LAN9645X_GCB_FEAT_DISABLE, LAN9645X_GCB_FEAT_DISABLE),
> +};
> +
> +static const struct regmap_access_table lan9645x_gcb_rd_table = {
> +	.yes_ranges = lan9645x_gcb_rd_ranges,
> +	.n_yes_ranges = ARRAY_SIZE(lan9645x_gcb_rd_ranges),
> +};
> +
> +static const struct regmap_range lan9645x_gcb_wr_no_ranges[] = {
> +	regmap_reg_range(0, LAN9645X_GCB_RES_SIZE - 1),
> +};
> +
> +static const struct regmap_access_table lan9645x_gcb_wr_table = {
> +	.no_ranges = lan9645x_gcb_wr_no_ranges,
> +	.n_no_ranges = ARRAY_SIZE(lan9645x_gcb_wr_no_ranges),
> +};
> +
> +static const struct regmap_range lan9645x_chip_top_ranges[] = {
> +	regmap_reg_range(LAN9645X_CHIP_TOP_CUPHY_PORT_STAT,
> +			 LAN9645X_CHIP_TOP_CUPHY_LED_CFG(4)),
> +	regmap_reg_range(LAN9645X_CHIP_TOP_STRAPPING,
> +			 LAN9645X_CHIP_TOP_STRAPPING),
> +};
> +
> +static const struct regmap_access_table lan9645x_chip_top_table = {
> +	.yes_ranges = lan9645x_chip_top_ranges,
> +	.n_yes_ranges = ARRAY_SIZE(lan9645x_chip_top_ranges),
> +};
> +
> +struct ocelot_regmap_access {
> +	const char *name;
> +	const struct regmap_access_table *rd_table;
> +	const struct regmap_access_table *wr_table;
> +};
> +
> +static const struct ocelot_regmap_access lan9645x_regmap_access[] = {
> +	{
> +		.name = "gcb",
> +		.rd_table = &lan9645x_gcb_rd_table,
> +		.wr_table = &lan9645x_gcb_wr_table,
> +	}, {
> +		.name = "chip_top",
> +		.rd_table = &lan9645x_chip_top_table,
> +		.wr_table = &lan9645x_chip_top_table,
> +	},
> +};
> +
>  struct ocelot_cells {
>  	const struct mfd_cell *cells;
>  	unsigned int num_cells;
> +	const struct ocelot_regmap_access *access;

I'm more than a little perturbed by all of these ocelot structs of
structs, etc.  Surely there's a better way to represent than this?

What about instead of indexing into an array of 'struct ocelot_cells'
wrapper structs and string-matching resource names against a separate
'struct ocelot_regmap_access' array, we can select the 'mfd_cell' array
directly with a switch() on an integer provided via .data in
ocelot_core_init().

However, the bigger issue: why is the MFD core driver creating 27
device-specific regmaps (and encoding child-specific register access
restriction tables like 'FEAT_DISABLE' and 'CUPHY_LED_CFG') on behalf of
its children in the first place?  In MFD, resources that are not shared
between multiple children should be initialised by the child drivers
that actually use them.

Asking AI for specifics:

  Even where regmaps are initialised here, 'gcb' and 'chip_top' are only
  listed in 'lan9645x_switch_resources' - no other child uses those regmap
  names because the MIIM and pinctrl children create their own sub-range
  regmaps ('gcb_gpio', 'gcb_miim0', 'gcb_phy'). If the switch driver owns
  the 'gcb' and 'chip_top' regmaps (or simply restricts its own access to
  the registers it cares about), 'struct ocelot_regmap_access' and the
  access table lookup in MFD disappear completely.

  Even if the regmap creation stays here, we can drop both 'struct
  ocelot_cells' and 'struct ocelot_regmap_access' by using a switch()
  (as we normally require for MFD cell selection anyway) and a small
  helper or switch for the two special cases:

    switch (ddata->chip) {
    case OCELOT_CHIP_LAN9645X:
            cells = lan9645x_devs;
            num_cells = ARRAY_SIZE(lan9645x_devs);
            break;
    case OCELOT_CHIP_VSC7512:
            cells = vsc7512_devs;
            num_cells = ARRAY_SIZE(vsc7512_devs);
            break;
    default:
            return -EINVAL;
    }

  Note also in ocelot-spi.c that 'lan9645x_spi_data' and
  'vsc7512_spi_data' are being passed through 'of_device_id.data' and
  'spi_device_id.driver_data' (introduced in Patch 1), whereas our
  convention is to pass the 'enum ocelot_chip' ID via match data and match
  on it with a switch() statement rather than piping driver structs
  through match tables.

> +	unsigned int num_access;
>  };
>  
>  static const struct ocelot_cells ocelot_cells[] = {
> +	[OCELOT_CHIP_LAN9645X] = {
> +		.cells = lan9645x_devs,
> +		.num_cells = ARRAY_SIZE(lan9645x_devs),
> +		.access = lan9645x_regmap_access,
> +		.num_access = ARRAY_SIZE(lan9645x_regmap_access),
> +	},
>  	[OCELOT_CHIP_VSC7512] = {
>  		.cells = vsc7512_devs,
>  		.num_cells = ARRAY_SIZE(vsc7512_devs),
> @@ -225,21 +422,35 @@ static const struct ocelot_cells ocelot_cells[] = {
>  };
>  
>  static void ocelot_core_try_add_regmap(struct device *dev,
> +				       const struct ocelot_cells *c,
>  				       const struct resource *res)
>  {
> +	const struct regmap_access_table *rd_table = NULL;
> +	const struct regmap_access_table *wr_table = NULL;
> +	int i;
> +
>  	if (dev_get_regmap(dev, res->name))
>  		return;
>  
> -	ocelot_spi_init_regmap(dev, res);
> +	for (i = 0; i < c->num_access; i++) {
> +		if (!strcmp(c->access[i].name, res->name)) {
> +			rd_table = c->access[i].rd_table;
> +			wr_table = c->access[i].wr_table;
> +			break;
> +		}
> +	}
> +
> +	ocelot_spi_init_regmap(dev, res, rd_table, wr_table);
>  }
>  
>  static void ocelot_core_try_add_regmaps(struct device *dev,
> +					const struct ocelot_cells *c,
>  					const struct mfd_cell *cell)
>  {
>  	int i;
>  
>  	for (i = 0; i < cell->num_resources; i++)
> -		ocelot_core_try_add_regmap(dev, &cell->resources[i]);
> +		ocelot_core_try_add_regmap(dev, c, &cell->resources[i]);
>  }
>  
>  int ocelot_core_init(struct device *dev)
> @@ -251,7 +462,7 @@ int ocelot_core_init(struct device *dev)
>  	c = &ocelot_cells[ddata->chip];
>  
>  	for (i = 0; i < c->num_cells; i++)
> -		ocelot_core_try_add_regmaps(dev, &c->cells[i]);
> +		ocelot_core_try_add_regmaps(dev, c, &c->cells[i]);
>  
>  	return devm_mfd_add_devices(dev, PLATFORM_DEVID_AUTO, c->cells, c->num_cells,
>  				    NULL, 0, NULL);
> diff --git a/drivers/mfd/ocelot-spi.c b/drivers/mfd/ocelot-spi.c
> index e803d0363e62..6d405627136d 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");
> +
>  struct ocelot_spi_data {
>  	enum ocelot_chip chip;
>  	const struct resource *cpuorg_res;
> @@ -57,6 +68,7 @@ struct ocelot_spi_data {
>  	unsigned int if_cfgstat;
>  	u32 if_cfgstat_si;
>  	const struct resource *gcb_res;
> +	int reset_padding_bytes;
>  	int (*padding_bytes)(u32 max_speed_hz);
>  };
>  
> @@ -74,6 +86,27 @@ 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)
> +{
> +	u32 khz = max_speed_hz / HZ_PER_KHZ;
> +
> +	/*
> +	 * 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(khz * LAN9645X_REG_ACCESS_TIME_US + 1500, 8000);
> +}
> +
> +static const struct ocelot_spi_data lan9645x_spi_data = {
> +	.chip = OCELOT_CHIP_LAN9645X,
> +	.cpuorg_res = &lan9645x_gcb_resource,
> +	.if_ctrl = LAN9645X_IF_CTRL,
> +	.if_cfgstat = LAN9645X_IF_CFGSTAT,
> +	.gcb_res = &lan9645x_gcb_resource,
> +	.reset_padding_bytes = LAN9645X_RESET_PADDING_BYTES,
> +	.padding_bytes = lan9645x_spi_padding_bytes,
> +};
> +
>  static const struct ocelot_spi_data vsc7512_spi_data = {
>  	.chip = OCELOT_CHIP_VSC7512,
>  	.cpuorg_res = &vsc7512_dev_cpuorg_resource,
> @@ -142,7 +175,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 | data->if_cfgstat_si;
>  
> @@ -215,7 +249,10 @@ static const struct regmap_bus ocelot_spi_regmap_bus = {
>  	.read = ocelot_spi_regmap_bus_read,
>  };
>  
> -struct regmap *ocelot_spi_init_regmap(struct device *dev, const struct resource *res)
> +struct regmap *ocelot_spi_init_regmap(struct device *dev,
> +				      const struct resource *res,
> +				      const struct regmap_access_table *rd_table,
> +				      const struct regmap_access_table *wr_table)
>  {
>  	struct regmap_config regmap_config;
>  
> @@ -224,6 +261,8 @@ struct regmap *ocelot_spi_init_regmap(struct device *dev, const struct resource
>  	regmap_config.name = res->name;
>  	regmap_config.max_register = resource_size(res) - 1;
>  	regmap_config.reg_base = res->start;
> +	regmap_config.rd_table = rd_table;
> +	regmap_config.wr_table = wr_table;
>  
>  	return devm_regmap_init(dev, &ocelot_spi_regmap_bus, dev, &regmap_config);
>  }
> @@ -234,6 +273,7 @@ static int ocelot_spi_probe(struct spi_device *spi)
>  	const struct ocelot_spi_data *data;
>  	struct device *dev = &spi->dev;
>  	struct ocelot_ddata *ddata;
> +	int padding, dummy_len;
>  	struct regmap *r;
>  	int err;
>  
> @@ -249,9 +289,15 @@ static int ocelot_spi_probe(struct spi_device *spi)
>  
>  	spi_set_drvdata(spi, ddata);
>  
> -	ddata->spi_padding_bytes = data->padding_bytes(spi->max_speed_hz);
> -	if (ddata->spi_padding_bytes) {
> -		ddata->dummy_buf = devm_kzalloc(dev, ddata->spi_padding_bytes, GFP_KERNEL);
> +	padding = data->padding_bytes(spi->max_speed_hz);
> +	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, data->reset_padding_bytes);
> +	if (dummy_len) {
> +		ddata->dummy_buf = devm_kzalloc(dev, dummy_len, GFP_KERNEL);
>  		if (!ddata->dummy_buf)
>  			return -ENOMEM;
>  	}
> @@ -262,15 +308,17 @@ 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, data->cpuorg_res);
> +	r = ocelot_spi_init_regmap(dev, data->cpuorg_res, NULL, NULL);
>  	if (IS_ERR(r))
>  		return PTR_ERR(r);
>  
>  	ddata->cpuorg_regmap = r;
>  
> -	r = ocelot_spi_init_regmap(dev, data->gcb_res);
> -	if (IS_ERR(r))
> -		return PTR_ERR(r);
> +	if (data->gcb_res != data->cpuorg_res) {
> +		r = ocelot_spi_init_regmap(dev, data->gcb_res, NULL, NULL);
> +		if (IS_ERR(r))
> +			return PTR_ERR(r);
> +	}
>  
>  	ddata->gcb_regmap = r;
>  
> @@ -279,6 +327,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 = data->reset_padding_bytes ?: padding;
> +
>  	err = ocelot_spi_initialize(dev, data);
>  	if (err)
>  		return dev_err_probe(dev, err, "Error initializing SPI bus\n");
> @@ -291,6 +341,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, data);
>  	if (err)
>  		return dev_err_probe(dev, err, "Error initializing SPI bus after reset\n");
> @@ -303,12 +355,19 @@ static int ocelot_spi_probe(struct spi_device *spi)
>  }
>  
>  static const struct spi_device_id ocelot_spi_ids[] = {
> +	{ .name = "lan96455f", .driver_data = (kernel_ulong_t)&lan9645x_spi_data },
> +	{ .name = "lan96455s", .driver_data = (kernel_ulong_t)&lan9645x_spi_data },
> +	{ .name = "lan96457f", .driver_data = (kernel_ulong_t)&lan9645x_spi_data },
> +	{ .name = "lan96457s", .driver_data = (kernel_ulong_t)&lan9645x_spi_data },
> +	{ .name = "lan96459f", .driver_data = (kernel_ulong_t)&lan9645x_spi_data },
> +	{ .name = "lan96459s", .driver_data = (kernel_ulong_t)&lan9645x_spi_data },
>  	{ .name = "vsc7512", .driver_data = (kernel_ulong_t)&vsc7512_spi_data },
>  	{ }
>  };
>  MODULE_DEVICE_TABLE(spi, ocelot_spi_ids);
>  
>  static const struct of_device_id ocelot_spi_of_match[] = {
> +	{ .compatible = "microchip,lan96455s", .data = &lan9645x_spi_data },
>  	{ .compatible = "mscc,vsc7512", .data = &vsc7512_spi_data },
>  	{ }
>  };
> diff --git a/drivers/mfd/ocelot.h b/drivers/mfd/ocelot.h
> index 92b5b893ff9b..fa02590a5026 100644
> --- a/drivers/mfd/ocelot.h
> +++ b/drivers/mfd/ocelot.h
> @@ -8,9 +8,14 @@
>  
>  struct device;
>  struct regmap;
> +struct regmap_access_table;
>  struct resource;
>  
> +#define LAN9645X_GCB_RES_START		0x00004000
> +#define LAN9645X_GCB_RES_SIZE		0x00000244
> +
>  enum ocelot_chip {
> +	OCELOT_CHIP_LAN9645X,
>  	OCELOT_CHIP_VSC7512,
>  };
>  
> @@ -23,10 +28,11 @@ enum ocelot_chip {
>   *			like SPI bus configuration.
>   * @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;
> @@ -41,7 +47,9 @@ int ocelot_core_init(struct device *dev);
>  
>  /* SPI-specific routines that won't be necessary for other interfaces */
>  struct regmap *ocelot_spi_init_regmap(struct device *dev,
> -				      const struct resource *res);
> +				      const struct resource *res,
> +				      const struct regmap_access_table *rd_table,
> +				      const struct regmap_access_table *wr_table);
>  
>  #define OCELOT_SPI_BYTE_ORDER_LE 0x00000000
>  #define OCELOT_SPI_BYTE_ORDER_BE 0x81818181
> 
> -- 
> 2.52.0
> 

-- 
Lee Jones

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

* Re: [PATCH 4/4] mfd: ocelot: Read LAN9645x registers in a single SPI transfer
  2026-11-23 13:25 ` [PATCH 4/4] mfd: ocelot: Read LAN9645x registers in a single SPI transfer Jens Emil Schulz Østergaard
@ 2026-12-02 13:35   ` Lee Jones
  0 siblings, 0 replies; 8+ messages in thread
From: Lee Jones @ 2026-12-02 13:35 UTC (permalink / raw)
  To: Jens Emil Schulz Østergaard
  Cc: Colin Foster, UNGLinuxDriver, Rob Herring, Krzysztof Kozlowski,
	Conor Dooley, Richard Cochran, mfd, linux-kernel, netdev,
	devicetree

On Mon, 23 Nov 2026, Jens Emil Schulz Østergaard wrote:

> 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 transfer
> buffer is allocated per regmap, so the regmap lock serializes its use.
>
> 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>
> ---
>  drivers/mfd/ocelot-spi.c | 92 ++++++++++++++++++++++++++++++++++++++++++++++--
>  drivers/mfd/ocelot.h     |  3 +-
>  2 files changed, 92 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/mfd/ocelot-spi.c b/drivers/mfd/ocelot-spi.c
> index 6d405627136d..4f2ef847c909 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,
> @@ -70,6 +76,12 @@ struct ocelot_spi_data {
>  	const struct resource *gcb_res;
>  	int reset_padding_bytes;
>  	int (*padding_bytes)(u32 max_speed_hz);
> +	bool single_xfer_read;
> +};
> +
> +struct ocelot_spi_regmap_ctx {
> +	struct device *dev;
> +	u8 buf[OCELOT_SPI_XFER_BUF_SIZE] __aligned(ARCH_DMA_MINALIGN);
>  };
>
>  static int vsc7512_spi_padding_bytes(u32 max_speed_hz)
> @@ -105,6 +117,7 @@ static const struct ocelot_spi_data lan9645x_spi_data = {
>  	.gcb_res = &lan9645x_gcb_resource,
>  	.reset_padding_bytes = LAN9645X_RESET_PADDING_BYTES,
>  	.padding_bytes = lan9645x_spi_padding_bytes,
> +	.single_xfer_read = true,
>  };
>
>  static const struct ocelot_spi_data vsc7512_spi_data = {
> @@ -249,12 +262,78 @@ 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 spi_transfer xfer = {};
> +	struct ocelot_ddata *ddata;
> +	const u8 *regu8 = reg;
> +	u8 *buf = ctx->buf;
> +	u8 *valu8 = val;
> +	size_t off;
> +	int err;
> +
> +	ddata = dev_get_drvdata(ctx->dev);

Define and initialise this at the top.

> +
> +	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;
> +
> +	buf[0] = regu8[0];
> +	buf[1] = regu8[1];
> +	buf[2] = regu8[2];
> +	memset(&buf[OCELOT_SPI_ADDR_SIZE], 0,
> +	       ddata->spi_padding_bytes + OCELOT_SPI_VAL_SIZE);

Why not use memcpy()?  Or start from a pre-initialised space?

> +	xfer.tx_buf = buf;
> +	xfer.rx_buf = buf;
> +	xfer.len = off + OCELOT_SPI_VAL_SIZE;
> +
> +	err = spi_sync_transfer(to_spi_device(ctx->dev), &xfer, 1);
> +	if (err)
> +		return err;
> +
> +	valu8[0] = buf[off + 0];
> +	valu8[1] = buf[off + 1];
> +	valu8[2] = buf[off + 2];
> +	valu8[3] = buf[off + 3];

memcpy()?

> +
> +	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_single_xfer_read(struct spi_device *spi,
> +					const struct ocelot_spi_data *data)
> +{
> +	return data->single_xfer_read &&
> +	       !(spi->controller->flags & SPI_CONTROLLER_HALF_DUPLEX) &&
> +	       !(spi->mode & SPI_3WIRE);
> +}
> +
>  struct regmap *ocelot_spi_init_regmap(struct device *dev,
>  				      const struct resource *res,
>  				      const struct regmap_access_table *rd_table,
>  				      const struct regmap_access_table *wr_table)
>  {
> +	struct spi_device *spi = to_spi_device(dev);
>  	struct regmap_config regmap_config;
> +	struct ocelot_spi_regmap_ctx *ctx;
>
>  	memcpy(&regmap_config, &ocelot_spi_regmap_config, sizeof(regmap_config));
>
> @@ -264,7 +343,16 @@ struct regmap *ocelot_spi_init_regmap(struct device *dev,
>  	regmap_config.rd_table = rd_table;
>  	regmap_config.wr_table = wr_table;
>
> -	return devm_regmap_init(dev, &ocelot_spi_regmap_bus, dev, &regmap_config);
> +	if (!ocelot_spi_single_xfer_read(spi, spi_get_device_match_data(spi)))
> +		return devm_regmap_init(dev, &ocelot_spi_regmap_bus, dev, &regmap_config);

Needs a comment.

> +	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");
>
> @@ -296,7 +384,7 @@ static int ocelot_spi_probe(struct spi_device *spi)
>  				     spi->max_speed_hz, OCELOT_SPI_MAX_PADDING_BYTES);
>
>  	dummy_len = max(padding, data->reset_padding_bytes);
> -	if (dummy_len) {
> +	if (!ocelot_spi_single_xfer_read(spi, data) && dummy_len) {

Comment.

>  		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 fa02590a5026..5d0301f0b194 100644
> --- a/drivers/mfd/ocelot.h
> +++ b/drivers/mfd/ocelot.h
> @@ -32,7 +32,8 @@ enum ocelot_chip {
>   *			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.
> + *			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;
>
> -- 
> 2.52.0
>

-- 
Lee Jones

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

end of thread, other threads:[~2026-12-02 13:35 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-23 13:25 [PATCH 0/4] mfd: ocelot: Support the LAN9645x switch family Jens Emil Schulz Østergaard
2026-11-23 13:25 ` [PATCH 1/4] mfd: ocelot: Select the chip through match data Jens Emil Schulz Østergaard
2026-12-02 12:34   ` Lee Jones
2026-11-23 13:25 ` [PATCH 2/4] dt-bindings: mfd: Add the Microchip LAN9645x switch family Jens Emil Schulz Østergaard
2026-11-23 13:25 ` [PATCH 3/4] mfd: ocelot: Add support for the " Jens Emil Schulz Østergaard
2026-12-02 13:28   ` Lee Jones
2026-11-23 13:25 ` [PATCH 4/4] mfd: ocelot: Read LAN9645x registers in a single SPI transfer Jens Emil Schulz Østergaard
2026-12-02 13:35   ` Lee Jones

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox