From: Andy Shevchenko <andriy.shevchenko@intel.com>
To: srini@kernel.org
Cc: gregkh@linuxfoundation.org, linux-kernel@vger.kernel.org,
Heiko Stuebner <heiko@sntech.de>
Subject: Re: [PATCH 3/8] nvmem: Add driver for the eeprom in qnap-mcu controllers
Date: Wed, 26 Nov 2025 14:42:02 +0100 [thread overview]
Message-ID: <aScDqsBMAc_TeDVE@black.igk.intel.com> (raw)
In-Reply-To: <20251114110636.143268-4-srini@kernel.org>
On Fri, Nov 14, 2025 at 11:06:31AM +0000, srini@kernel.org wrote:
>
> The qnap-mcu also has an eeprom connected to it, that contains some
> specific product-information like the mac addresses for the network
> interfaces.
>
> Add a nvmem driver for it.
I have no problem with current code, but below some hints in case you want to
improve it.
...
+ device.h
+ err.h
> +#include <linux/mfd/qnap-mcu.h>
> +#include <linux/module.h>
> +#include <linux/nvmem-provider.h>
> +#include <linux/platform_device.h>
> +#include <linux/slab.h>
+ string.h
+ types.h
...
> +static int qnap_mcu_eeprom_read_block(struct qnap_mcu *mcu, unsigned int offset,
> + void *val, size_t bytes)
> +{
> + const u8 cmd[] = { 0xf7, 0xa1, offset, bytes };
> + u8 *reply;
> + int ret = 0;
> +
> + reply = kzalloc(bytes + sizeof(cmd), GFP_KERNEL);
> + if (!reply)
> + return -ENOMEM;
Using __free() from cleanup.h actually fits here and makes code easier to read.
> + ret = qnap_mcu_exec(mcu, cmd, sizeof(cmd), reply, bytes + sizeof(cmd));
> + if (ret)
> + goto out;
> +
> + /* First bytes must mirror the sent command */
> + if (memcmp(cmd, reply, sizeof(cmd))) {
> + ret = -EIO;
> + goto out;
> + }
> +
> + memcpy(val, reply + sizeof(cmd), bytes);
> +
> +out:
> + kfree(reply);
> + return ret;
> +}
...
> +static int qnap_mcu_eeprom_probe(struct platform_device *pdev)
> +{
struct device *parent = pdev->dev.parent;
> + struct qnap_mcu *mcu = dev_get_drvdata(pdev->dev.parent);
struct qnap_mcu *mcu = dev_get_drvdata(parent);
> + struct nvmem_config nvcfg = {};
> + struct nvmem_device *ndev;
> +
> + nvcfg.dev = &pdev->dev;
> + nvcfg.of_node = pdev->dev.parent->of_node;
nvcfg.of_node = dev_of_node(parent);
(will need to include of.h, but ideally nvmem can be switched to fwnode)
> + nvcfg.name = dev_name(&pdev->dev);
> + nvcfg.id = NVMEM_DEVID_NONE;
> + nvcfg.owner = THIS_MODULE;
> + nvcfg.type = NVMEM_TYPE_EEPROM;
> + nvcfg.read_only = true;
> + nvcfg.root_only = false;
> + nvcfg.reg_read = qnap_mcu_eeprom_read;
> + nvcfg.size = QNAP_MCU_EEPROM_SIZE,
> + nvcfg.word_size = 1,
> + nvcfg.stride = 1,
> + nvcfg.priv = mcu,
> +
> + ndev = devm_nvmem_register(&pdev->dev, &nvcfg);
> + if (IS_ERR(ndev))
> + return PTR_ERR(ndev);
> +
> + return 0;
retrun PTR_ERR_OR_ZERO(...);
> +}
--
With Best Regards,
Andy Shevchenko
next prev parent reply other threads:[~2025-11-26 13:42 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-14 11:06 [PATCH 0/8] nvmem: patches for 6.19 srini
2025-11-14 11:06 ` [PATCH 1/8] dt-bindings: nvmem: qfprom: Add sa8775p compatible srini
2025-11-14 11:06 ` [PATCH 2/8] dt-bindings: nvmem: Support MediaTek MT8189 evb board efuse srini
2025-11-14 11:06 ` [PATCH 3/8] nvmem: Add driver for the eeprom in qnap-mcu controllers srini
2025-11-26 13:42 ` Andy Shevchenko [this message]
2025-11-14 11:06 ` [PATCH 4/8] nvmem: layouts: u-boot-env: add optional "env-size" property srini
2025-11-14 11:06 ` [PATCH 5/8] dt-bindings: nvmem: mediatek: efuse: Add compatible for MT8189 SoC srini
2025-11-14 11:06 ` [PATCH 6/8] dt-bindings: nvmem: don't check node names srini
2025-11-14 11:06 ` [PATCH 7/8] dt-bindings: nvmem: imx-ocotp: Add support for i.MX94 srini
2025-11-14 11:06 ` [PATCH 8/8] nvmem: imx-ocotp-ele: Add i.MX94 OCOTP support srini
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=aScDqsBMAc_TeDVE@black.igk.intel.com \
--to=andriy.shevchenko@intel.com \
--cc=gregkh@linuxfoundation.org \
--cc=heiko@sntech.de \
--cc=linux-kernel@vger.kernel.org \
--cc=srini@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