Re: [PATCH 3/4] mfd: ocelot: Add support for the LAN9645x switch family

From: Jens Emil Schulz Østergaard

Date: Thu Dec 03 2026 - 05:47:17 EST


On Wed Dec 2, 2026 at 2:28 PM CET, Lee Jones wrote:

[...]

>> +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_*

Will do.

[...]

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

Agreed. With the changes to patch 1 the cells are selected with a
switch() on the chip passed through .data, and struct ocelot_cells is
gone. This patch only adds the LAN9645x case.

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

The access tables were only there to keep the switch driver away from
the registers of the other children. v2 drops them together with
struct ocelot_regmap_access, and the switch driver only accesses the
registers it uses.

The LAN9645x children follow the pattern established for the VSC7512.
The child drivers were written for memory mapped targets, with register
offsets relative to the target. The child drivers cannot create a regmap
on the SPI bus themselves, so the core creates one regmap per resource.

mdio-mscc-miim, pinctrl-ocelot and pinctrl-microchip-sgpio get theirs
with ocelot_regmap_from_resource(), which takes the resource of the
child by index and returns the regmap the parent created for it. The
LAN9645x support reuses mdio-mscc-miim and pinctrl-ocelot. The LAN9645x
switch driver gets its regmaps from the parent by name, same as felix does
for the VSC7512 switch.

[...]