[PATCH V3 2/2] nvmem: add driver handling U-Boot environment variables

Miquel Raynal miquel.raynal at bootlin.com
Tue Jun 14 02:02:30 PDT 2022


Hello,

> > +static int u_boot_env_probe(struct platform_device *pdev)
> > +{
> > +	struct nvmem_config config = {
> > +		.name = "u-boot-env",
> > +		.reg_read = u_boot_env_read,
> > +	};
> > +	struct device *dev = &pdev->dev;
> > +	struct device_node *np = dev->of_node;
> > +	const struct of_device_id *of_id;
> > +	struct u_boot_env *priv;
> > +	int err;
> > +
> > +	priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
> > +	if (!priv)
> > +		return -ENOMEM;
> > +	priv->dev = dev;
> > +
> > +	of_id = of_match_device(u_boot_env_of_match_table, dev);
> > +	if (!of_id)
> > +		return -EINVAL;
> > +	priv->format = (uintptr_t)of_id->data;
> > +
> > +	if (of_property_read_u32(np, "reg", (u32 *)&priv->offset) ||
> > +	    of_property_read_u32_index(np, "reg", 1, (u32 *)&priv->size)) {
> > +		dev_err(dev, "Failed to read \"reg\" property\n");
> > +		return -EINVAL;
> > +	}
> > +
> > +	priv->mtd = of_get_mtd_device_by_node(np->parent);
> > +	if (IS_ERR(priv->mtd)) {
> > +		dev_err(dev, "Failed to get %pOF MTD: %ld\n", np->parent, PTR_ERR(priv->mtd));
> > +		return PTR_ERR(priv->mtd);
> > +	}  
> 
> Partitions are mtd devices themselves and the mtd layer directly
> associates these devices to their OF node, so it should be possible
> to do a of_get_mtd_device_by_node(np) which gets you the partition.
> You can use the whole mtd device then and do not have to fiddle with
> reg properties, offsets and sizes in your driver yourself.

Just for the record, there will be one mtd device per partition, but
the "full" mtd device will only exist if the configuration contains
CONFIG_MTD_PARTITIONED_MASTER.

Thanks,
Miquèl



More information about the linux-arm-kernel mailing list