Re: [PATCH 1/4] mfd: ocelot: Select the chip through match data
From: Jens Emil Schulz Østergaard
Date: Thu Dec 03 2026 - 05:33:39 EST
On Wed Dec 2, 2026 at 1:34 PM CET, Lee Jones wrote:
> 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.
Thanks for the review.
[...]
>> +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
Will do. In v2 ocelot_core_init() selects the cells with a switch() on
ddata->chip, and the soft reset register is selected the same way
instead of through the ocelot_soft_rst[] table. A separate patch before
this one will convert the existing VSC7512 cells to MFD_CELL_OF() and
MFD_CELL_OF_REG().
[...]
>> + for (i = 0; i < c->num_cells; i++)
>
> for (int i = 0; ...
Will do.
[...]
>
>> -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?
Yes, in the next version the OF and SPI match tables will only carry the enum
ocelot_chip value, and the probe sets the chip specific values in a
switch() on it.
>
>> + 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.
Understood, the padding calculation will be called from the case of
the chip in that switch().