[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAPaKu7TVeaEFRWBt7rF_uVUyYO72GHqFwKi7D52juPTRAk7URw@mail.gmail.com>
Date: Fri, 19 Dec 2025 17:04:22 -0800
From: Chia-I Wu <olvaffe@...il.com>
To: Nicolas Frattaroli <nicolas.frattaroli@...labora.com>
Cc: Boris Brezillon <boris.brezillon@...labora.com>, Steven Price <steven.price@....com>,
Liviu Dudau <liviu.dudau@....com>, Maarten Lankhorst <maarten.lankhorst@...ux.intel.com>,
Maxime Ripard <mripard@...nel.org>, Thomas Zimmermann <tzimmermann@...e.de>,
David Airlie <airlied@...il.com>, Simona Vetter <simona@...ll.ch>, Rob Herring <robh@...nel.org>,
Krzysztof Kozlowski <krzk+dt@...nel.org>, Conor Dooley <conor+dt@...nel.org>,
Matthias Brugger <matthias.bgg@...il.com>,
AngeloGioacchino Del Regno <angelogioacchino.delregno@...labora.com>,
Ulf Hansson <ulf.hansson@...aro.org>, Chen-Yu Tsai <wenst@...omium.org>, kernel@...labora.com,
dri-devel@...ts.freedesktop.org, devicetree@...r.kernel.org,
linux-kernel@...r.kernel.org, linux-arm-kernel@...ts.infradead.org,
linux-mediatek@...ts.infradead.org, linux-pm@...r.kernel.org
Subject: Re: [PATCH 4/4] pmdomain: mediatek: mtk-mfg: Expose shader_present as
nvmem cell
On Wed, Dec 17, 2025 at 9:04 AM Nicolas Frattaroli
<nicolas.frattaroli@...labora.com> wrote:
>
> Implement nvmem-provider functionality in mtk-mfg-pmdomain, such that it
> can expose its GF_REG_SHADER_PRESENT value in the shared memory as an
> nvmem cell for panthor.
>
> Signed-off-by: Nicolas Frattaroli <nicolas.frattaroli@...labora.com>
> ---
> drivers/pmdomain/mediatek/mtk-mfg-pmdomain.c | 57 ++++++++++++++++++++++++++++
> 1 file changed, 57 insertions(+)
>
> diff --git a/drivers/pmdomain/mediatek/mtk-mfg-pmdomain.c b/drivers/pmdomain/mediatek/mtk-mfg-pmdomain.c
> index 9bad577b3ae4..725ebc678f1b 100644
> --- a/drivers/pmdomain/mediatek/mtk-mfg-pmdomain.c
> +++ b/drivers/pmdomain/mediatek/mtk-mfg-pmdomain.c
> @@ -10,6 +10,7 @@
> #include <linux/clk-provider.h>
> #include <linux/container_of.h>
> #include <linux/iopoll.h>
> +#include <linux/nvmem-provider.h>
> #include <linux/mailbox_client.h>
> #include <linux/module.h>
> #include <linux/of.h>
> @@ -872,6 +873,58 @@ static int mtk_mfg_init_clk_provider(struct mtk_mfg *mfg)
> return 0;
> }
>
> +static int mtk_mfg_read_nvmem(void *priv, unsigned int offset, void *val, size_t bytes)
> +{
> + struct mtk_mfg *mfg = priv;
> + u32 *buf = val;
> +
> + if (bytes != 4)
> + return -EINVAL;
> +
> + if (!mfg->shared_mem)
> + return -ENODEV;
> +
> + if (offset + bytes >= mfg->shared_mem_size)
> + return -EINVAL;
> +
> + *buf = readl(mfg->shared_mem + offset);
> +
> + return 0;
> +}
> +
> +static int mtk_mfg_init_nvmem_provider(struct mtk_mfg *mfg)
> +{
> + struct device *dev = &mfg->pdev->dev;
> + struct nvmem_cell_info cell = {};
> + struct nvmem_config config = {};
> + struct nvmem_device *nvdev;
> + int ret;
> +
> + config.reg_read = mtk_mfg_read_nvmem;
> + config.dev = dev;
> + config.read_only = true;
> + config.priv = mfg;
> + config.size = 4;
> + config.word_size = 4;
> +
> + nvdev = devm_nvmem_register(dev, &config);
> + of_node_put(config.of_node);
This looks like a dead line.
> + if (IS_ERR(nvdev))
> + return dev_err_probe(dev, PTR_ERR(nvdev), "Couldn't register nvmem provider\n");
> +
> + cell.name = "shader-present";
> + cell.offset = GF_REG_SHADER_PRESENT;
> + cell.bytes = 4;
> + cell.np = of_get_child_by_name(dev->of_node, cell.name);
> +
> + ret = nvmem_add_one_cell(nvdev, &cell);
> + /* cell.np purposefully not put as nvmem_add_one_cell does not increase refcount */
I think you still need to of_node_put on errors.
> + if (ret)
> + return dev_err_probe(dev, ret, "Couldn't add cell %s\n", cell.name);
> +
> + return 0;
> +}
> +
> static int mtk_mfg_probe(struct platform_device *pdev)
> {
> struct mtk_mfg *mfg;
> @@ -984,6 +1037,10 @@ static int mtk_mfg_probe(struct platform_device *pdev)
> if (ret)
> goto err_power_off;
>
> + ret = mtk_mfg_init_nvmem_provider(mfg);
> + if (ret)
> + goto err_power_off;
> +
> ret = of_genpd_add_provider_simple(dev->of_node, &mfg->pd);
> if (ret) {
> dev_err_probe(dev, ret, "Failed to add pmdomain provider\n");
>
> --
> 2.52.0
>
Powered by blists - more mailing lists