From 254409dbe836633b079968c0e7686ecd09b45dc7 Mon Sep 17 00:00:00 2001 From: Lukasz Majewski Date: Mon, 3 Dec 2018 10:20:47 +0100 Subject: nand: vybrid: Use calloc() instead of malloc() to allocate struct nfc Without this change it is possible that Vybrid's NFC driver malloc() call will obtain some memory used (and correctly free'd) by some previous driver (in this case pinctrl for Vybrid). As a result some fields of struct nfc - in out case mtd->_get_device - are "pre initialized" with some random values. On the latter stage of booting, when e.g. somebody calls 'mtdparts default' the "data abort" is observed when __get_mtd_device() function is called. The mtd->_get_device pointer is not NULL and wrong value is referenced. Signed-off-by: Lukasz Majewski Reviewed-by: Stefan Agner --- drivers/mtd/nand/raw/vf610_nfc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers/mtd/nand/raw/vf610_nfc.c') diff --git a/drivers/mtd/nand/raw/vf610_nfc.c b/drivers/mtd/nand/raw/vf610_nfc.c index 619d0403e9..9baf5fa37a 100644 --- a/drivers/mtd/nand/raw/vf610_nfc.c +++ b/drivers/mtd/nand/raw/vf610_nfc.c @@ -641,7 +641,7 @@ static int vf610_nfc_nand_init(int devnum, void __iomem *addr) .flash_bbt = 1, }; - nfc = malloc(sizeof(*nfc)); + nfc = calloc(1, sizeof(*nfc)); if (!nfc) { printf(KERN_ERR "%s: Memory exhausted!\n", __func__); return -ENOMEM; -- cgit From acdf10e17937f4b23fb2613e148caf25aac62c37 Mon Sep 17 00:00:00 2001 From: Lukasz Majewski Date: Mon, 3 Dec 2018 10:24:51 +0100 Subject: nand: vybrid: Extend the vf610 NFC NAND driver to support device tree (and DM) This commit adds support for device tree and enumeration via device model for the Vybrid's NFC NAND driver. Signed-off-by: Lukasz Majewski --- drivers/mtd/nand/raw/vf610_nfc.c | 47 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) (limited to 'drivers/mtd/nand/raw/vf610_nfc.c') diff --git a/drivers/mtd/nand/raw/vf610_nfc.c b/drivers/mtd/nand/raw/vf610_nfc.c index 9baf5fa37a..3326c2b096 100644 --- a/drivers/mtd/nand/raw/vf610_nfc.c +++ b/drivers/mtd/nand/raw/vf610_nfc.c @@ -31,6 +31,11 @@ #include #include #include +#if CONFIG_NAND_VF610_NFC_DT +#include +#include +#include +#endif /* Register Offsets */ #define NFC_FLASH_CMD1 0x3F00 @@ -760,9 +765,51 @@ error: return err; } +#if CONFIG_NAND_VF610_NFC_DT +static const struct udevice_id vf610_nfc_dt_ids[] = { + { + .compatible = "fsl,vf610-nfc", + }, + { /* sentinel */ } +}; + +static int vf610_nfc_dt_probe(struct udevice *dev) +{ + struct resource res; + int ret; + + ret = dev_read_resource(dev, 0, &res); + if (ret) + return ret; + + return vf610_nfc_nand_init(0, devm_ioremap(dev, res.start, + resource_size(&res))); +} + +U_BOOT_DRIVER(vf610_nfc_dt) = { + .name = "vf610-nfc-dt", + .id = UCLASS_MTD, + .of_match = vf610_nfc_dt_ids, + .probe = vf610_nfc_dt_probe, +}; + +void board_nand_init(void) +{ + struct udevice *dev; + int ret; + + ret = uclass_get_device_by_driver(UCLASS_MTD, + DM_GET_DRIVER(vf610_nfc_dt), + &dev); + if (ret && ret != -ENODEV) + pr_err("Failed to initialize NAND controller. (error %d)\n", + ret); +} +#else void board_nand_init(void) { int err = vf610_nfc_nand_init(0, (void __iomem *)CONFIG_SYS_NAND_BASE); if (err) printf("VF610 NAND init failed (err %d)\n", err); } +#endif /* CONFIG_NAND_VF610_NFC_DT */ -- cgit