HI Jagan,

On 2015年11月07日 20:35, Jagan Teki wrote:
It seems we are working toward the same direction. :)

Sorry, I couldn't understand this looks we're in different direction.

Let me explain what I thought about mtd_info usage. udevice should be
part of underlying flash structure's like cfi, nand and spi_flash and
mtd_info should be used for it's core api's like _erase. _read and
_write and underlying driver will use their global structure that
include's mtd and udevice as a function pointer like this.

Please see v5 of this patch and v3 of altera qspi.

The uclass priv of mtd class is an auto-allocated mtd_info. The spi_flash_priv includes both mtd_info and spi_flash. So the only difference is the spi_flash. This is because cfi uses struct flash, while spi flash uses struct spi_flash. So it is better to leave the struct flash to driver allocation.

The mtd->priv points to struct spi_flash for spi flash, and points to struct flash for cfi flash. It serves the same purpose.

The struct flash has *mtd. The struct spi_flash has *mtd, too.

I added struct udevice *dev to mtd_info. The struct spi_flash has *dev, but struct flash has not.


struct spi_flash {
    struct mtd_info *info;
    struct udevice *device;
}


struct flash {
...
struct mtd_info *info;
}

struct spi_flash_priv {
         struct spi_flash        flash;
         struct mtd_info         mtd;
};


Simply,
struct mtd_info.


static int spi_flash_std_probe(struct udevice *dev)
{
         struct spi_flash_priv *priv = dev_get_uclass_priv(dev);
         struct spi_slave *spi = dev_get_parent_priv(dev);
         struct spi_flash *flash;
         int ret;

         flash = &priv->flash;
         flash->mtd = &priv->mtd;

mtd = dev_get_uclass_priv(dev);
flash->mtd = mtd;


         flash->spi = spi;
         flash->priv = priv;

         priv->mtd.priv = flash;
         flash->dev = dev;

mtd->priv = flash;
mtd->dev = dev;

flash->mtd->dev is the same as spi's flash->dev

}

U_BOOT_DRIVER(spi_flash_std) = {
         .name           = "spi_flash_std",
         .id             = UCLASS_SPI_FLASH,
         .of_match       = spi_flash_std_ids,
         .probe          = spi_flash_std_probe,
         .priv_auto_alloc_size = sizeof(struct spi_flash_priv),
};

This is the way I have implemented mtd on spi-flash[1] [2]
[1] https://patchwork.ozlabs.org/patch/529397/
[2] https://patchwork.ozlabs.org/patch/529399/

Please explain how this related your approach of adding udevice to mtd.


The flash ops which u-boot commands calls are built upon mtd ops.

eg,
write_buff()
{
  mtd_write();
}

flash_erase()
{
  mtd_erase();
}

Please let me know what do you think. Thanks. :)

Best regards,
Thomas
_______________________________________________
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot

Reply via email to