From: "Jens Emil Schulz Østergaard" <jensemil.schulzostergaard@microchip.com>
To: "Lee Jones" <lee@kernel.org>,
"Jens Emil Schulz Østergaard"
<jensemil.schulzostergaard@microchip.com>
Cc: Colin Foster <colin.foster@in-advantage.com>,
<UNGLinuxDriver@microchip.com>, Rob Herring <robh@kernel.org>,
"Krzysztof Kozlowski" <krzk+dt@kernel.org>,
Conor Dooley <conor+dt@kernel.org>,
"Richard Cochran" <richardcochran@gmail.com>,
<mfd@lists.linux.dev>, <linux-kernel@vger.kernel.org>,
<netdev@vger.kernel.org>, <devicetree@vger.kernel.org>
Subject: Re: [PATCH 4/4] mfd: ocelot: Read LAN9645x registers in a single SPI transfer
Date: Thu, 3 Dec 2026 11:54:19 +0100 [thread overview]
Message-ID: <DNB1IY7PUUEH.SX2T668D5OV8@microchip.com> (raw)
In-Reply-To: <179568544891.32537.5068972183702816273@kernel.org>
On Wed Dec 2, 2026 at 2:35 PM CET, Lee Jones wrote:
> On Mon, 23 Nov 2026, Jens Emil Schulz Østergaard wrote:
[...]
>> +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.
Will do.
>> +
>> + 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?
The address will be copied with memcpy() in v2.
The memset() is there because the buffer is both tx_buf and rx_buf, so
every read overwrites the padding bytes with the received data. In v2
the transmit and receive buffers are separate. The transmit buffer is
zeroed once when it is allocated, and a read only copies the address
into it.
[...]
>> + valu8[0] = buf[off + 0];
>> + valu8[1] = buf[off + 1];
>> + valu8[2] = buf[off + 2];
>> + valu8[3] = buf[off + 3];
>
> memcpy()?
Will do.
[...]
>> - return devm_regmap_init(dev, &ocelot_spi_regmap_bus, dev, ®map_config);
>> + if (!ocelot_spi_single_xfer_read(spi, spi_get_device_match_data(spi)))
>> + return devm_regmap_init(dev, &ocelot_spi_regmap_bus, dev, ®map_config);
>
> Needs a comment.
I will add one.
>
>> + 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, ®map_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.
I will add one.
prev parent reply other threads:[~2026-12-03 10:54 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
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-12-03 10:33 ` 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 ` [PATCH 3/4] mfd: ocelot: Add support for the " Jens Emil Schulz Østergaard
2026-12-02 13:28 ` Lee Jones
2026-12-03 10:47 ` 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
2026-12-02 13:35 ` Lee Jones
2026-12-03 10:54 ` Jens Emil Schulz Østergaard [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=DNB1IY7PUUEH.SX2T668D5OV8@microchip.com \
--to=jensemil.schulzostergaard@microchip.com \
--cc=UNGLinuxDriver@microchip.com \
--cc=colin.foster@in-advantage.com \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=krzk+dt@kernel.org \
--cc=lee@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mfd@lists.linux.dev \
--cc=netdev@vger.kernel.org \
--cc=richardcochran@gmail.com \
--cc=robh@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®