@@ -85,7 +85,7 @@ static int do_spi_flash_probe(int argc, char * const argv[])
unsigned int speed = CONFIG_SF_DEFAULT_SPEED;
unsigned int mode = CONFIG_SF_DEFAULT_MODE;
char *endp;
-#ifdef CONFIG_DM_SPI_FLASH
+#if defined(CONFIG_DM_SPI_FLASH) || defined (CONFIG_MTD_DM_SPI_NOR)
struct udevice *new, *bus_dev;
int ret;
#else
@@ -118,7 +118,7 @@ static int do_spi_flash_probe(int argc, char * const argv[])
return -1;
}
-#ifdef CONFIG_DM_SPI_FLASH
+#if defined(CONFIG_DM_SPI_FLASH) || defined (CONFIG_MTD_DM_SPI_NOR)
/* Remove the old device, otherwise probe will just be a nop */
ret = spi_find_bus_and_cs(bus, cs, &bus_dev, &new);
if (!ret) {
@@ -1,5 +1,6 @@
menuconfig MTD_SPI_NOR
tristate "SPI-NOR device support"
+ select MTD_DM_SPI_NOR
help
This is the core SPI NOR framework which can be used to interact SPI-NOR
to SPI driver interface layer and the SPI-NOR controller driver.
@@ -12,6 +13,10 @@ menuconfig MTD_SPI_NOR
SPI-NOR controller drivers for SPI-NOR device access. Note that from SPI-NOR
core to SPI drivers there should be an interface layer.
+config MTD_DM_SPI_NOR
+ tristate
+ depends on DM_SPI && MTD
+
if MTD_SPI_NOR
config MTD_M25P80
@@ -6,6 +6,8 @@
ifdef CONFIG_MTD_SPI_NOR
obj-y += spi-nor.o
obj-y += spi-nor-ids.o
+
+obj-$(CONFIG_MTD_DM_SPI_NOR) += spi-nor-probe.o
endif
obj-$(CONFIG_MTD_M25P80) += m25p80.o
new file mode 100644
@@ -0,0 +1,30 @@
+/*
+ * Copyright (c) 2014 Google, Inc
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <spi.h>
+#include <spi_flash.h>
+
+int spi_flash_probe_bus_cs(unsigned int busnum, unsigned int cs,
+ unsigned int max_hz, unsigned int spi_mode,
+ struct udevice **devp)
+{
+ struct spi_slave *slave;
+ struct udevice *bus;
+ char name[30], *str;
+ int ret;
+
+ snprintf(name, sizeof(name), "spi-nor@%d:%d", busnum, cs);
+ str = strdup(name);
+ ret = spi_get_bus_and_cs(busnum, cs, max_hz, spi_mode,
+ "m25p80", str, &bus, &slave);
+ if (ret)
+ return ret;
+
+ *devp = slave->dev;
+ return 0;
+}
@@ -190,6 +190,12 @@ int sandbox_sf_bind_emul(struct sandbox_state *state, int busnum, int cs,
void sandbox_sf_unbind_emul(struct sandbox_state *state, int busnum, int cs);
+#elif CONFIG_MTD_DM_SPI_NOR
+
+int spi_flash_probe_bus_cs(unsigned int busnum, unsigned int cs,
+ unsigned int max_hz, unsigned int spi_mode,
+ struct udevice **devp);
+
#else
struct spi_flash *spi_flash_probe(unsigned int bus, unsigned int cs,
unsigned int max_hz, unsigned int spi_mode);
This patch adds driver-model probe from cmd_sf through MTD_DM_SPI_NOR which is depends on MTD and DM_SPI uclass. Cc: Simon Glass <sjg@chromium.org> Cc: Bin Meng <bmeng.cn@gmail.com> Cc: Mugunthan V N <mugunthanvnm@ti.com> Cc: Michal Simek <michal.simek@xilinx.com> Cc: Siva Durga Prasad Paladugu <sivadur@xilinx.com> Signed-off-by: Jagan Teki <jteki@openedev.com> --- cmd/sf.c | 4 ++-- drivers/mtd/spi-nor/Kconfig | 5 +++++ drivers/mtd/spi-nor/Makefile | 2 ++ drivers/mtd/spi-nor/spi-nor-probe.c | 30 ++++++++++++++++++++++++++++++ include/spi_flash.h | 6 ++++++ 5 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 drivers/mtd/spi-nor/spi-nor-probe.c