@@ -1,6 +1,6 @@
menuconfig MTD_SPI_NAND
bool "SPI NAND device Support"
- depends on DM_MTD && DM_SPI
+ depends on (DM_MTD && DM_SPI) || (MTD && SPI)
select MTD_NAND_CORE
select SPI_MEM
help
@@ -170,14 +170,22 @@ int spinand_select_target(struct spinand_device *spinand, unsigned int target)
static int spinand_init_cfg_cache(struct spinand_device *spinand)
{
struct nand_device *nand = spinand_to_nand(spinand);
+#ifdef CONFIG_DM
struct udevice *dev = spinand->slave->dev;
+#endif
unsigned int target;
int ret;
+#ifdef CONFIG_DM
spinand->cfg_cache = devm_kzalloc(dev,
sizeof(*spinand->cfg_cache) *
nand->memorg.ntargets,
GFP_KERNEL);
+#else
+ spinand->cfg_cache = kzalloc(sizeof(*spinand->cfg_cache) *
+ nand->memorg.ntargets,
+ GFP_KERNEL);
+#endif
if (!spinand->cfg_cache)
return -ENOMEM;
@@ -1135,6 +1144,7 @@ static void spinand_cleanup(struct spinand_device *spinand)
kfree(spinand->scratchbuf);
}
+#ifdef CONFIG_DM
static int spinand_probe(struct udevice *dev)
{
struct spinand_device *spinand = dev_get_priv(dev);
@@ -1187,6 +1197,40 @@ err_spinand_cleanup:
return ret;
}
+#endif /* CONFIG_DM */
+
+#ifdef __UBOOT__
+int spinand_probe_no_dm(struct spinand_device *spinand,
+ struct spi_slave *slave,
+ struct mtd_info *mtd)
+{
+ struct nand_device *nand = spinand_to_nand(spinand);
+ int ret;
+
+ nand->mtd = mtd;
+ mtd->priv = nand;
+ mtd->name = malloc(20);
+ if (!mtd->name)
+ return -ENOMEM;
+ sprintf(mtd->name, "spi-nand%d", spi_nand_idx++);
+ spinand->slave = slave;
+
+ ret = spinand_init(spinand);
+ if (ret)
+ return ret;
+
+ ret = add_mtd_device(mtd);
+ if (ret)
+ goto err_spinand_cleanup;
+
+ return 0;
+
+err_spinand_cleanup:
+ spinand_cleanup(spinand);
+
+ return ret;
+}
+#endif /* __UBOOT__ */
#ifndef __UBOOT__
static int spinand_remove(struct udevice *slave)
@@ -1238,6 +1282,7 @@ MODULE_AUTHOR("Peter Pan<peterpandong at micron.com>");
MODULE_LICENSE("GPL v2");
#endif /* __UBOOT__ */
+#ifdef CONFIG_DM
static const struct udevice_id spinand_ids[] = {
{ .compatible = "spi-nand" },
{ /* sentinel */ },
@@ -1250,3 +1295,4 @@ U_BOOT_DRIVER(spinand) = {
.priv_auto_alloc_size = sizeof(struct spinand_device),
.probe = spinand_probe,
};
+#endif /* CONFIG_DM */