mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Patrice CHOTARD <patrice.chotard@foss.st.com>
To: Krzysztof Kozlowski <krzk@kernel.org>
Cc: Rob Herring <robh@kernel.org>,
	Krzysztof Kozlowski <krzk+dt@kernel.org>,
	Conor Dooley <conor+dt@kernel.org>,
	Maxime Coquelin <mcoquelin.stm32@gmail.com>,
	Alexandre Torgue <alexandre.torgue@foss.st.com>,
	Christophe Roullier <christophe.roullier@foss.st.com>,
	Srinivas Kandagatla <srini@kernel.org>,
	Simeon Marijon <simeon.marijon@foss.st.com>,
	<linux-stm32@st-md-mailman.stormreply.com>,
	<devicetree@vger.kernel.org>,
	<linux-arm-kernel@lists.infradead.org>,
	<linux-kernel@vger.kernel.org>,
	Gatien Chevallier <gatien.chevallier@foss.st.com>
Subject: Re: [PATCH v3 3/3] nvmem: stm32: add TAMP nvmem driver
Date: Wed, 4 Nov 2026 14:43:42 +0100	[thread overview]
Message-ID: <87bca3a4-e12d-4160-9a92-0944d078e942@foss.st.com> (raw)
In-Reply-To: <20261017-positive-curassow-from-sirius-c283c0@quoll>



On 10/17/26 19:57, Krzysztof Kozlowski wrote:
> On Fri, Oct 16, 2026 at 05:26:05PM +0200, Patrice Chotard wrote:
>> +static int stm32_tamp_nvram_probe(struct platform_device *pdev)
>> +{
>> +	struct device *dev = &pdev->dev;
>> +	struct stm32_tamp_nvram_priv *priv;
>> +	struct resource *res;
>> +	struct device_node *of_node;
>> +	const struct of_device_id *of_id;
>> +	void __iomem *base_addr;
>> +	int *zones_end;
>> +
>> +	priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
>> +	if (!priv)
>> +		return -ENOMEM;
>> +
>> +	priv->dev = &pdev->dev;
>> +
>> +	of_node = dev_of_node(dev);
>> +	if (!of_node) {
>> +		dev_err(dev, "Can't get of node of the device\n");
>> +		return -ENODEV;
> 
> Entire dev_of_node and if() look not necessary.

Ok

> 
>> +	}
>> +
>> +	of_id = of_match_node(stm32_tamp_nvram_of_match, of_node);
>> +	if (!of_id) {
>> +		dev_err(dev, "Can't get of_id of the device\n");
>> +		return -ENODEV;
>> +	}
>> +
>> +	priv->data = (struct stm32_tamp_nvram_plat *)of_id->data;
> 
> Use wrapper - device_get_match_data or something similar (don't remember
> exactly).

Ok> 
>> +	if (!priv->data) {
>> +		dev_err(dev, "Can't get platform data of the node\n");
>> +		return -ENODEV;
>> +	}
>> +
>> +	priv->config_regmap = syscon_node_to_regmap(dev->parent->of_node);
>> +	if (IS_ERR(priv->config_regmap))
>> +		return dev_err_probe(dev, PTR_ERR(priv->config_regmap),
>> +				     "Can't get TAMP syscon regmap\n");
>> +
>> +	priv->idx_bkpreg_zones_end = stm32_tamp_nvram_get_backup_zones(priv);
>> +	if (IS_ERR(priv->idx_bkpreg_zones_end))
>> +		return dev_err_probe(dev, PTR_ERR(priv->idx_bkpreg_zones_end),
>> +				     "Can't determine protection zone\n");
>> +
>> +	zones_end = priv->idx_bkpreg_zones_end;
>> +	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
>> +
> 
> Drop blank line

Ok> 
>> +	if (!res) {
>> +		dev_err(dev, "Can't get resource\n");
>> +		return -ENODEV;
>> +	}
>> +
>> +	base_addr = devm_ioremap_resource(dev, res);
> 
> You cannot use wrapper over these two? And I am a bit confused - device
> takes syscon from the parent, so how does it map also another memory?

This part will be reworked. On patch 2 of DT series [1], sashiko made a similar 
remark regarding the overlapping parent syscon's memory region.
I will address this point in next revision.

[1] https://patchwork.kernel.org/project/linux-arm-kernel/patch/20260930-upstream_tamp_nvram_dts_part-v2-2-bd73158ce46b@foss.st.com/

> 
>> +	if (IS_ERR(base_addr)) {
>> +		dev_err(dev, "Can't remap resource\n");
>> +		return PTR_ERR(base_addr);
>> +	}
>> +
>> +	priv->cfg.name = "stm32-tamp-nvram";
>> +	priv->cfg.word_size = 1;
>> +	priv->cfg.stride = 1;
>> +	priv->cfg.dev = dev;
>> +	priv->cfg.priv = priv;
>> +	priv->cfg.owner = THIS_MODULE;
>> +	priv->cfg.type = NVMEM_TYPE_BATTERY_BACKED;
>> +	priv->cfg.size = resource_size(res);
>> +	priv->cfg.reg_read = stm32_tamp_nvram_read;
>> +	priv->cfg.reg_write = stm32_tamp_nvram_write;
>> +
>> +	if (priv->data->nb_zones == NB_ZONES_STM32MP2) {
>> +		priv->bkpreg_access = stm32_tamp_get_access_rights_mp2x(priv);
>> +
>> +		if (IS_ERR(priv->bkpreg_access))
>> +			return PTR_ERR(priv->bkpreg_access);
>> +
>> +		dev_dbg(dev, "\n"
>> +			"Zone 1-RIF1 %3d - %3d %c%c\n"
>> +			"Zone 1-RIF2 %3d - %3d %c%c\n"
>> +			"Zone 2-RIF1 %3d - %3d %c%c\n"
>> +			"Zone 2-RIF2 %3d - %3d %c%c\n"
>> +			"Zone 3-RIF1 %3d - %3d %c%c\n"
>> +			"Zone 3-RIF0 %3d - %3d %c%c\n"
>> +			"Zone 3-RIF2 %3d - %3d %c%c\n",
>> +			0,
>> +			zones_end[BKPREG_PROTECTION_ZONE_1_RIF1],
>> +			stm32_tamp_nvram_rights(priv,
>> +						zones_end[BKPREG_PROTECTION_ZONE_1_RIF1],
>> +						true) ? 'R' : '-',
>> +			stm32_tamp_nvram_rights(priv,
>> +						zones_end[BKPREG_PROTECTION_ZONE_1_RIF1],
>> +						false) ? 'W' : '-',
>> +			zones_end[BKPREG_PROTECTION_ZONE_1_RIF1] + 1,
>> +			zones_end[BKPREG_PROTECTION_ZONE_1_RIF2],
>> +			stm32_tamp_nvram_rights(priv,
>> +						zones_end[BKPREG_PROTECTION_ZONE_1_RIF2],
>> +						true) ? 'R' : '-',
>> +			stm32_tamp_nvram_rights(priv,
>> +						zones_end[BKPREG_PROTECTION_ZONE_1_RIF2],
>> +						false) ? 'W' : '-',
>> +			zones_end[BKPREG_PROTECTION_ZONE_1_RIF2] + 1,
>> +			zones_end[BKPREG_PROTECTION_ZONE_2_RIF1],
>> +			stm32_tamp_nvram_rights(priv,
>> +						zones_end[BKPREG_PROTECTION_ZONE_2_RIF1],
>> +						true) ? 'R' : '-',
>> +			stm32_tamp_nvram_rights(priv,
>> +						zones_end[BKPREG_PROTECTION_ZONE_2_RIF1],
>> +						false) ? 'W' : '-',
>> +			zones_end[BKPREG_PROTECTION_ZONE_2_RIF1] + 1,
>> +			zones_end[BKPREG_PROTECTION_ZONE_2_RIF2],
>> +			stm32_tamp_nvram_rights(priv,
>> +						zones_end[BKPREG_PROTECTION_ZONE_2_RIF2],
>> +						true) ? 'R' : '-',
>> +			stm32_tamp_nvram_rights(priv,
>> +						zones_end[BKPREG_PROTECTION_ZONE_2_RIF2],
>> +						false) ? 'W' : '-',
>> +			zones_end[BKPREG_PROTECTION_ZONE_2_RIF2] + 1,
>> +			zones_end[BKPREG_PROTECTION_ZONE_3_RIF1],
>> +			stm32_tamp_nvram_rights(priv,
>> +						zones_end[BKPREG_PROTECTION_ZONE_3_RIF1],
>> +						true) ? 'R' : '-',
>> +			stm32_tamp_nvram_rights(priv,
>> +						zones_end[BKPREG_PROTECTION_ZONE_3_RIF1],
>> +						false) ? 'W' : '-',
>> +			zones_end[BKPREG_PROTECTION_ZONE_3_RIF1] + 1,
>> +			zones_end[BKPREG_PROTECTION_ZONE_3_RIF0],
>> +			stm32_tamp_nvram_rights(priv,
>> +						zones_end[BKPREG_PROTECTION_ZONE_3_RIF0],
>> +						true) ? 'R' : '-',
>> +			stm32_tamp_nvram_rights(priv,
>> +						zones_end[BKPREG_PROTECTION_ZONE_3_RIF0],
>> +						false) ? 'W' : '-',
>> +			zones_end[BKPREG_PROTECTION_ZONE_3_RIF0] + 1,
>> +			zones_end[BKPREG_PROTECTION_ZONE_3_RIF2],
>> +			stm32_tamp_nvram_rights(priv,
>> +						zones_end[BKPREG_PROTECTION_ZONE_3_RIF2],
>> +						true) ? 'R' : '-',
>> +			stm32_tamp_nvram_rights(priv,
>> +						zones_end[BKPREG_PROTECTION_ZONE_3_RIF2],
>> +						false) ? 'W' : '-'
>> +				);
>> +	} else if (priv->data->nb_zones == NB_ZONES_STM32MP1) {
>> +		priv->bkpreg_access = stm32mp1_tamp_bkpreg_access;
>> +
>> +		dev_dbg(dev, "\n"
>> +			"Zone 1 %3d - %3d %c%c\n"
>> +			"Zone 2 %3d - %3d %c%c\n"
>> +			"Zone 3 %3d - %3d %c%c\n",
>> +			0,
>> +			zones_end[BKPREG_PROTECTION_ZONE_1],
>> +			stm32_tamp_nvram_rights(priv,
>> +						zones_end[BKPREG_PROTECTION_ZONE_1],
>> +						true) ? 'R' : '-',
>> +			stm32_tamp_nvram_rights(priv,
>> +						zones_end[BKPREG_PROTECTION_ZONE_1],
>> +						false) ? 'W' : '-',
>> +			zones_end[BKPREG_PROTECTION_ZONE_1] + 1,
>> +			zones_end[BKPREG_PROTECTION_ZONE_2],
>> +			stm32_tamp_nvram_rights(priv,
>> +						zones_end[BKPREG_PROTECTION_ZONE_2],
>> +						true) ? 'R' : '-',
>> +			stm32_tamp_nvram_rights(priv,
>> +						zones_end[BKPREG_PROTECTION_ZONE_2],
>> +						false) ? 'W' : '-',
>> +			zones_end[BKPREG_PROTECTION_ZONE_2] + 1,
>> +			zones_end[BKPREG_PROTECTION_ZONE_3],
>> +			stm32_tamp_nvram_rights(priv,
>> +						zones_end[BKPREG_PROTECTION_ZONE_3],
>> +						true) ? 'R' : '-',
>> +			stm32_tamp_nvram_rights(priv,
>> +						zones_end[BKPREG_PROTECTION_ZONE_3],
>> +						false) ? 'W' : '-');
>> +	}
>> +
>> +	platform_set_drvdata(pdev, priv);
>> +	priv->bkpregs_regmap = devm_regmap_init_mmio(dev, base_addr,
>> +						     priv->data->bkpregs_regmap_cfg);
>> +	if (IS_ERR(priv->bkpregs_regmap)) {
>> +		dev_err(dev, "failed to init regmap: %ld\n", PTR_ERR(priv->bkpregs_regmap));
>> +		return PTR_ERR(priv->bkpregs_regmap);
> 
> return dev_err_probe

Ok

Thanks
Patrice

> 
> 
> Best regards,
> Krzysztof
> 

      reply	other threads:[~2026-11-04 13:43 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-16 15:26 [PATCH v3 0/3] Add STM32 TAMP nvram driver support Patrice Chotard
2026-10-16 15:26 ` [PATCH v3 1/3] dt-bindings: nvmem: add STM32MPX TAMP backup registers Patrice Chotard
2026-10-16 15:26 ` [PATCH v3 2/3] dt-bindings: arm: stm32: allow TAMP nvram child node for syscon Patrice Chotard
2026-10-17 17:52   ` Krzysztof Kozlowski
2026-11-04 13:43     ` Patrice CHOTARD
2026-10-16 15:26 ` [PATCH v3 3/3] nvmem: stm32: add TAMP nvmem driver Patrice Chotard
2026-10-17 17:57   ` Krzysztof Kozlowski
2026-11-04 13:43     ` Patrice CHOTARD [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=87bca3a4-e12d-4160-9a92-0944d078e942@foss.st.com \
    --to=patrice.chotard@foss.st.com \
    --cc=alexandre.torgue@foss.st.com \
    --cc=christophe.roullier@foss.st.com \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=gatien.chevallier@foss.st.com \
    --cc=krzk+dt@kernel.org \
    --cc=krzk@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-stm32@st-md-mailman.stormreply.com \
    --cc=mcoquelin.stm32@gmail.com \
    --cc=robh@kernel.org \
    --cc=simeon.marijon@foss.st.com \
    --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

all inboxes | Powered by JetHome®