Skip to contentSkip to conversation

mtd: spi-nor: Add dm spi-nor probing

PATCH New Jagan Teki 1 participant 1 message Feb 16, 2016

Subsystems (2)
lore
Share & tools
lore

Jagan Teki

author
#0 lore raw

PATCH v7 9/76 mtd: spi-nor: Add dm spi-nor probing

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 <[email protected]>
Cc Bin Meng <[email protected]>
Cc Mugunthan V N <[email protected]>
Cc Michal Simek <[email protected]>
Cc Siva Durga Prasad Paladugu <[email protected]>

---
Changes for v7:
- Rename CONFIG_MTD_DM_SPI_NOR to CONFIG_DM_MTD_SPI_NOR
- Fix proper kconfig select for CONFIG_MTD_DM_SPI_NOR

 cmd/sf.c                            |  4 ++--
 common/env_sf.c                     |  4 ++--
 drivers/mtd/spi-nor/Kconfig         |  7 +++++++
 drivers/mtd/spi-nor/Makefile        |  2 ++
 drivers/mtd/spi-nor/spi-nor-probe.c | 30 ++++++++++++++++++++++++++++++
 include/spi_flash.h                 | 11 ++++++++++-
 6 files changed, 53 insertions(+), 5 deletions(-)
 create mode 100644 drivers/mtd/spi-nor/spi-nor-probe.c
cmd/sf.c +2 -2
index 42862d9..528fc4d 100644
@@ -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_DM_MTD_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_DM_MTD_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) {
common/env_sf.c +2 -2
index 892e6cb..652ed0b 100644
@@ -52,7 +52,7 @@ int saveenv(void)
 	char	*saved_buffer = NULL, flag = OBSOLETE_FLAG;
 	u32	saved_size, saved_offset, sector = 1;
 	int	ret;
-#ifdef CONFIG_DM_SPI_FLASH
+#if defined(CONFIG_DM_SPI_FLASH) || defined (CONFIG_DM_MTD_SPI_NOR)
 	struct udevice *new;
 
 	ret = spi_flash_probe_bus_cs(CONFIG_ENV_SPI_BUS, CONFIG_ENV_SPI_CS,
@@ -242,7 +242,7 @@ int saveenv(void)
 	char	*saved_buffer = NULL;
 	int	ret = 1;
 	env_t	env_new;
-#ifdef CONFIG_DM_SPI_FLASH
+#if defined(CONFIG_DM_SPI_FLASH) || defined (CONFIG_DM_MTD_SPI_NOR)
 	struct udevice *new;
 
 	ret = spi_flash_probe_bus_cs(CONFIG_ENV_SPI_BUS, CONFIG_ENV_SPI_CS,
drivers/mtd/spi-nor/Kconfig +7 -0
index 374cdcb..342164d 100644
@@ -1,5 +1,6 @@
 menuconfig MTD_SPI_NOR
 	tristate "SPI-NOR device support"
+	select DM_MTD_SPI_NOR if DM_SPI && MTD
 	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,12 @@ 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 DM_MTD_SPI_NOR
+	bool "MTD driver model for SPI-NOR"
+	help
+	  This is enables MTD driver model support for SPI-NOR. Both MTD and SPI
+	  driver models need to define for enabling this support.
+
 if MTD_SPI_NOR
 
 config MTD_M25P80
drivers/mtd/spi-nor/Makefile +2 -0
index 9ab6e3d..2f41630 100644
@@ -6,6 +6,8 @@
 ifdef CONFIG_MTD_SPI_NOR
 obj-y += spi-nor.o
 obj-y += spi-nor-ids.o
+
+obj-$(CONFIG_DM_MTD_SPI_NOR)	+= spi-nor-probe.o
 endif
 
 obj-$(CONFIG_MTD_M25P80)	+= m25p80.o
drivers/mtd/spi-nor/spi-nor-probe.c new file +30 -0
new file mode 100644
index 0000000..c808a7d
@@ -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;
+}
include/spi_flash.h +10 -1
index d0ce9e7..af9f89b 100644
@@ -108,6 +108,14 @@ struct spi_flash {
 #endif
 };
 
+#if defined(CONFIG_MTD_SPI_NOR) && defined(CONFIG_DM_MTD_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);
+
+#endif
+
 struct dm_spi_flash_ops {
 	int (*read)(struct udevice *dev, u32 offset, size_t len, void *buf);
 	int (*write)(struct udevice *dev, u32 offset, size_t len,
@@ -190,7 +198,8 @@ 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);
 
-#else
+#elif !defined(CONFIG_MTD_SPI_NOR)
+
 struct spi_flash *spi_flash_probe(unsigned int bus, unsigned int cs,
 		unsigned int max_hz, unsigned int spi_mode);
 
Signature · 1 line
1.9.1