From: Jagan Teki <jteki@openedev.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v6 12/76] mtd: spi-nor: m25p80: Add spi_nor support for non-dm
Date: Mon, 15 Feb 2016 02:18:11 +0530 [thread overview]
Message-ID: <1455482955-19053-12-git-send-email-jteki@openedev.com> (raw)
In-Reply-To: <1455482955-19053-1-git-send-email-jteki@openedev.com>
Like adding spi_nor support for dm-driven code in m25p80
add the same way for non-dm code as well.
- allocate spi_nor{}
- basic initilization
- install hooks
- call to spi-nor core, using spi_nor_scan
- register with mtd core
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>
---
drivers/mtd/spi-nor/m25p80.c | 108 ++++++++++++++++++++++++++++++++++++++-----
include/spi_flash.h | 18 +++++++-
2 files changed, 112 insertions(+), 14 deletions(-)
diff --git a/drivers/mtd/spi-nor/m25p80.c b/drivers/mtd/spi-nor/m25p80.c
index 57e54d0..f0340a5 100644
--- a/drivers/mtd/spi-nor/m25p80.c
+++ b/drivers/mtd/spi-nor/m25p80.c
@@ -19,6 +19,9 @@
struct m25p {
struct spi_slave *spi;
struct spi_nor spi_nor;
+#ifndef CONFIG_MTD_DM_SPI_NOR
+ struct mtd_info mtd;
+#endif
};
static int spi_read_then_write(struct spi_slave *spi, const u8 *cmd,
@@ -179,16 +182,13 @@ static int m25p80_write(struct spi_nor *nor, const u8 *cmd, size_t cmd_len,
return ret;
}
-static int m25p_probe(struct udevice *dev)
+static int m25p80_spi_nor(struct spi_nor *nor)
{
- struct spi_slave *spi = dev_get_parent_priv(dev);
- struct mtd_info *mtd = dev_get_uclass_priv(dev);
- struct m25p *flash = dev_get_priv(dev);
- struct spi_nor *nor;
+ struct mtd_info *mtd = nor->mtd;
+ struct m25p *flash = nor->priv;
+ struct spi_slave *spi = flash->spi;
int ret;
- nor = &flash->spi_nor;
-
/* install hooks */
nor->read_mmap = m25p80_read_mmap;
nor->read = m25p80_read;
@@ -196,10 +196,6 @@ static int m25p_probe(struct udevice *dev)
nor->read_reg = m25p80_read_reg;
nor->write_reg = m25p80_write_reg;
- nor->mtd = mtd;
- nor->priv = flash;
- flash->spi = spi;
-
/* claim spi bus */
ret = spi_claim_bus(spi);
if (ret) {
@@ -251,10 +247,33 @@ err_scan:
spi_release_bus(spi);
err_mtd:
spi_free_slave(spi);
- device_remove(dev);
return ret;
}
+#ifdef CONFIG_MTD_DM_SPI_NOR
+static int m25p_probe(struct udevice *dev)
+{
+ struct spi_slave *spi = dev_get_parent_priv(dev);
+ struct mtd_info *mtd = dev_get_uclass_priv(dev);
+ struct m25p *flash = dev_get_priv(dev);
+ struct spi_nor *nor;
+ int ret;
+
+ nor = &flash->spi_nor;
+
+ nor->mtd = mtd;
+ nor->priv = flash;
+ flash->spi = spi;
+
+ ret = m25p80_spi_nor(nor);
+ if (ret) {
+ device_remove(dev);
+ return ret;
+ }
+
+ return 0;
+}
+
static const struct udevice_id m25p_ids[] = {
/*
* Generic compatibility for SPI NOR that can be identified by the
@@ -271,3 +290,68 @@ U_BOOT_DRIVER(m25p80) = {
.probe = m25p_probe,
.priv_auto_alloc_size = sizeof(struct m25p),
};
+
+#else
+
+static struct mtd_info *m25p80_probe_tail(struct spi_slave *bus)
+{
+ struct m25p *flash;
+ struct spi_nor *nor;
+ int ret;
+
+ flash = calloc(1, sizeof(*flash));
+ if (!flash) {
+ debug("mp25p80: failed to allocate m25p\n");
+ return NULL;
+ }
+
+ nor = &flash->spi_nor;
+ nor->mtd = &flash->mtd;
+
+ nor->priv = flash;
+ flash->spi = bus;
+
+ ret = m25p80_spi_nor(nor);
+ if (ret) {
+ free(flash);
+ return NULL;
+ }
+
+ return nor->mtd;
+}
+
+struct mtd_info *spi_flash_probe(unsigned int busnum, unsigned int cs,
+ unsigned int max_hz, unsigned int spi_mode)
+{
+ struct spi_slave *bus;
+
+ bus = spi_setup_slave(busnum, cs, max_hz, spi_mode);
+ if (!bus)
+ return NULL;
+ return m25p80_probe_tail(bus);
+}
+
+#ifdef CONFIG_OF_SPI_FLASH
+struct mtd_info *spi_flash_probe_fdt(const void *blob, int slave_node,
+ int spi_node)
+{
+ struct spi_slave *bus;
+
+ bus = spi_setup_slave_fdt(blob, slave_node, spi_node);
+ if (!bus)
+ return NULL;
+ return m25p80_probe_tail(bus);
+}
+#endif
+
+void spi_flash_free(struct mtd_info *info)
+{
+ struct spi_nor *nor = info->priv;
+ struct m25p *flash = nor->priv;
+
+ del_mtd_device(info);
+ spi_free_slave(flash->spi);
+ free(flash);
+}
+
+#endif /* CONFIG_MTD_DM_SPI_NOR */
diff --git a/include/spi_flash.h b/include/spi_flash.h
index e76ea11..1165199 100644
--- a/include/spi_flash.h
+++ b/include/spi_flash.h
@@ -108,10 +108,12 @@ struct spi_flash {
#endif
};
-#if defined(CONFIG_MTD_SPI_NOR) && defined(CONFIG_MTD_DM_SPI_NOR)
+#ifdef CONFIG_MTD_SPI_NOR
typedef struct mtd_info spi_flash_t;
+#ifdef 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);
@@ -123,7 +125,19 @@ spi_flash_t *spi_flash_probe(unsigned int bus, unsigned int cs,
/* Compatibility function - this is the old U-Boot API */
void spi_flash_free(spi_flash_t *flash);
-#endif
+#else
+
+spi_flash_t *spi_flash_probe(unsigned int bus, unsigned int cs,
+ unsigned int max_hz, unsigned int spi_mode);
+
+spi_flash_t *spi_flash_probe_fdt(const void *blob, int slave_node,
+ int spi_node);
+
+void spi_flash_free(spi_flash_t *flash);
+
+#endif /* CONFIG_MTD_DM_SPI_NOR */
+
+#endif /* CONFIG_MTD_SPI_NOR */
struct dm_spi_flash_ops {
int (*read)(struct udevice *dev, u32 offset, size_t len, void *buf);
--
1.9.1
next prev parent reply other threads:[~2016-02-14 20:48 UTC|newest]
Thread overview: 84+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-02-14 20:48 [U-Boot] [PATCH v6 01/76] mtd: Add m25p80 driver Jagan Teki
2016-02-14 20:48 ` [U-Boot] [PATCH v6 02/76] mtd: Add Kconfig entry for MTD_M25P80 Jagan Teki
2016-02-14 20:48 ` [U-Boot] [PATCH v6 03/76] mtd: Add SPI-NOR core support Jagan Teki
2016-02-14 20:48 ` [U-Boot] [PATCH v6 04/76] doc: device-tree-bindings: jedec, spi-nor Jagan Teki
2016-02-14 20:48 ` [U-Boot] [PATCH v6 05/76] mtd: spi-nor: Add Kconfig entry for MTD_SPI_NOR Jagan Teki
2016-02-14 20:48 ` [U-Boot] [PATCH v6 06/76] mtd: spi-nor: Add kconfig for MTD_SPI_NOR_USE_4K_SECTORS Jagan Teki
2016-02-14 20:48 ` [U-Boot] [PATCH v6 07/76] mtd: spi-nor: Add MTD support Jagan Teki
2016-02-14 20:48 ` [U-Boot] [PATCH v6 08/76] mtd: spi-nor: Add spi_nor support in m25p80 Jagan Teki
2016-02-14 20:48 ` [U-Boot] [PATCH v6 09/76] mtd: spi-nor: Add dm spi-nor probing Jagan Teki
2016-02-15 9:15 ` Jagan Teki
2016-02-14 20:48 ` [U-Boot] [PATCH v6 10/76] mtd: spi-nor: Add spi_flash_probe for mtd-dm-spi-nor Jagan Teki
2016-02-14 20:48 ` [U-Boot] [PATCH v6 11/76] mtd: spi-nor: Add spi_flash_free " Jagan Teki
2016-02-14 20:48 ` Jagan Teki [this message]
2016-02-14 20:48 ` [U-Boot] [PATCH v6 13/76] sf: Rename erase_size to erasesize Jagan Teki
2016-02-14 20:48 ` [U-Boot] [PATCH v6 14/76] sf: Use erasesize instead of sector_size Jagan Teki
2016-02-14 20:48 ` [U-Boot] [PATCH v6 15/76] sf: Use uint64_t for flash->size Jagan Teki
2016-02-14 20:48 ` [U-Boot] [PATCH v6 16/76] spi_flash: Use mtd_info operation for SPI-NOR Jagan Teki
2016-02-14 20:48 ` [U-Boot] [PATCH v6 17/76] spi_flash: Use spi_flash_t instead of struct spi_flash Jagan Teki
2016-02-14 20:48 ` [U-Boot] [PATCH v6 18/76] mtd: spi-nor: Move spi_read_then_write to spi layer Jagan Teki
2016-02-14 20:48 ` [U-Boot] [PATCH v6 19/76] spi: Rename spi_read_then_write to spi_write_then_read Jagan Teki
2016-02-14 20:48 ` [U-Boot] [PATCH v6 20/76] mtd: spi-nor: Rename SPI_FLASH_BAR to SPI_NOR_BAR Jagan Teki
2016-02-14 20:48 ` [U-Boot] [PATCH v6 21/76] mtd: spi-nor: Add Kconfig entry for SPI_NOR_BAR Jagan Teki
2016-02-14 20:48 ` [U-Boot] [PATCH v6 22/76] mtd: spi-nor: Copy spl files from drivers/mtd/spi Jagan Teki
2016-02-14 20:48 ` [U-Boot] [PATCH v6 23/76] mtd: spi-nor: spl: Follow ascending order of include headers Jagan Teki
2016-02-14 20:48 ` [U-Boot] [PATCH v6 24/76] mtd: spi-nor: fsl_espi_spl: Use mtd_info Jagan Teki
2016-02-14 20:48 ` [U-Boot] [PATCH v6 25/76] mtd: spi-nor: spi_spl_load: " Jagan Teki
2016-02-14 20:48 ` [U-Boot] [PATCH v6 26/76] mtd: spi-nor: Add flash vendor Kconfig entries Jagan Teki
2016-02-14 20:48 ` [U-Boot] [PATCH v6 27/76] arm: zynq: Kconfig: Select MTD uclass Jagan Teki
2016-02-14 20:48 ` [U-Boot] [PATCH v6 28/76] arm: zynq: Kconfig: Drop DM_SPI_FLASH Jagan Teki
2016-02-14 20:48 ` [U-Boot] [PATCH v6 29/76] defconfigs: zynq_microzed: Drop CONFIG_SPI_FLASH Jagan Teki
2016-02-14 20:48 ` [U-Boot] [PATCH v6 30/76] defconfig: zynq_microzed: Enable CONFIG_MTD_M25P80 Jagan Teki
2016-02-14 20:48 ` [U-Boot] [PATCH v6 31/76] defconfig: zynq_microzed: Enable CONFIG_MTD_SPI_NOR Jagan Teki
2016-02-14 20:48 ` [U-Boot] [PATCH v6 32/76] spl: Add CONFIG_SPL_SPI_NOR_SUPPORT Jagan Teki
2016-02-14 20:48 ` [U-Boot] [PATCH v6 33/76] configs: zynq: Use CONFIG_SPL_SPI_NOR_SUPPORT Jagan Teki
2016-02-14 20:48 ` [U-Boot] [PATCH v6 34/76] configs: zynq: Use CONFIG_SPL_MTD_SUPPORT Jagan Teki
2016-02-14 20:48 ` [U-Boot] [PATCH v6 35/76] mtd: spi-nor: Copy sf_dataflash Jagan Teki
2016-02-14 20:48 ` [U-Boot] [PATCH v6 36/76] mtd: dataflash: Remove unneeded spi data Jagan Teki
2016-02-14 20:48 ` [U-Boot] [PATCH v6 37/76] mtd: dataflash: Move flash id detection into jedec_probe Jagan Teki
2016-02-14 20:48 ` [U-Boot] [PATCH v6 38/76] mtd: dataflash: Fix add_dataflash return logic Jagan Teki
2016-02-14 20:48 ` [U-Boot] [PATCH v6 39/76] mtd: dataflash: Add UCLASS_MTD support Jagan Teki
2016-02-14 20:48 ` [U-Boot] [PATCH v6 40/76] mtd: dataflash: Use spi_write_then_read Jagan Teki
2016-02-14 20:48 ` [U-Boot] [PATCH v6 41/76] mtd: dataflash: Drop sf_internal.h Jagan Teki
2016-02-14 20:48 ` [U-Boot] [PATCH v6 42/76] mtd: dataflash: Minor cleanups Jagan Teki
2016-02-14 20:48 ` [U-Boot] [PATCH v6 43/76] mtd: Rename sf_dataflash.c to mtd_dataflash.c Jagan Teki
2016-02-14 20:48 ` [U-Boot] [PATCH v6 44/76] mtd: spi-nor: Add Kconfig entry for mtd_dataflash Jagan Teki
2016-02-14 20:48 ` [U-Boot] [PATCH v6 45/76] mtd: dataflash: Add MTD_DATAFLASH_WRITE_VERIFY Jagan Teki
2016-02-14 20:48 ` [U-Boot] [PATCH v6 46/76] mtd: spi-nor: Add kconfig MTD_DATAFLASH_WRITE_VERIFY Jagan Teki
2016-02-14 20:48 ` [U-Boot] [PATCH v6 47/76] configs: ls1021aqds: Drop DM_SPI_FLASH and DATAFLASH Jagan Teki
2016-02-14 20:48 ` [U-Boot] [PATCH v6 48/76] defconfig: ls1021aqds_qspi: Enable SPI-NOR Jagan Teki
2016-02-14 20:48 ` [U-Boot] [PATCH v6 49/76] defconfig: ls1021aqds_qspi: Enable CONFIG_MTD_DATAFLASH Jagan Teki
2016-02-14 20:48 ` [U-Boot] [PATCH v6 50/76] mtd: spi-nor: Copy sandbox Jagan Teki
2016-02-14 20:48 ` [U-Boot] [PATCH v6 51/76] mtd: spi-nor: sandbox: Use spi-nor header Jagan Teki
2016-02-14 20:48 ` [U-Boot] [PATCH v6 52/76] mtd: spi-nor: Add SPI_NOR_SANBOX Jagan Teki
2016-02-14 20:48 ` [U-Boot] [PATCH v6 53/76] sandbox: kconfig: Drop DM_SPI_FLASH Jagan Teki
2016-02-14 20:48 ` [U-Boot] [PATCH v6 54/76] sandbox: kconfig: Select MTD uclass Jagan Teki
2016-02-14 20:48 ` [U-Boot] [PATCH v6 55/76] defconfigs: sandbox: Enable SPI-NOR Jagan Teki
2016-02-14 20:48 ` [U-Boot] [PATCH v6 56/76] mtd: sandbox: Use CONFIG_MTD_SPI_NOR Jagan Teki
2016-02-14 20:48 ` [U-Boot] [PATCH v6 57/76] defconfigs: sandbox: Enable SPI_NOR_SANDBOX Jagan Teki
2016-02-14 20:48 ` [U-Boot] [PATCH v6 58/76] spi_flash: Use spi_flash_t Jagan Teki
2016-02-14 20:48 ` [U-Boot] [PATCH v6 59/76] mtd: spi-nor: Add CONFIG_SPI_NOR_MISC Jagan Teki
2016-02-14 20:48 ` [U-Boot] [PATCH v6 60/76] config: Enable SPI-NOR framework Jagan Teki
2016-02-14 20:49 ` [U-Boot] [PATCH v6 61/76] spi-nor: Use CONFIG_MTD_SPI_NOR Jagan Teki
2016-02-14 20:49 ` [U-Boot] [PATCH v6 62/76] configs: " Jagan Teki
2016-02-14 20:49 ` [U-Boot] [PATCH v6 63/76] configs: Use CONFIG_SPI_NOR_BAR Jagan Teki
2016-02-14 20:49 ` [U-Boot] [PATCH v6 64/76] configs: spi-nor: Add new flash vendor configs Jagan Teki
2016-02-14 20:49 ` [U-Boot] [PATCH v6 65/76] configs: Use CONFIG_SPI_NOR_MISC Jagan Teki
2016-02-17 8:53 ` Bin Meng
2016-02-17 9:05 ` Jagan Teki
2016-02-17 9:09 ` Bin Meng
2016-02-17 9:31 ` Jagan Teki
2016-02-14 20:49 ` [U-Boot] [PATCH v6 66/76] spi: Drop mode_rx Jagan Teki
2016-02-15 11:16 ` Bin Meng
2016-02-15 13:07 ` Jagan Teki
2016-02-16 1:08 ` Bin Meng
2016-02-14 20:49 ` [U-Boot] [PATCH v6 67/76] spi: Drop SPI_RX_FAST Jagan Teki
2016-02-14 20:49 ` [U-Boot] [PATCH v6 68/76] configs: Enable MTD uclass in missing configs Jagan Teki
2016-02-14 20:49 ` [U-Boot] [PATCH v6 69/76] configs: Drop CONFIG_SPI_FLASH_MTD Jagan Teki
2016-02-14 20:49 ` [U-Boot] [PATCH v6 70/76] uclass: Replace UCLASS_SPI_FLASH with UCLASS_MTD Jagan Teki
2016-02-14 20:49 ` [U-Boot] [PATCH v6 71/76] uclass: Drop UCLASS_SPI_FLASH Jagan Teki
2016-02-14 20:49 ` [U-Boot] [PATCH v6 72/76] configs: Use CONFIG_SPL_SPI_NOR_SUPPORT Jagan Teki
2016-02-14 20:49 ` [U-Boot] [PATCH v6 73/76] configs: Enable CONFIG_SPL_MTD_SUPPORT Jagan Teki
2016-02-14 20:49 ` [U-Boot] [PATCH v6 74/76] sf: Drop entire spi-flash framework Jagan Teki
2016-02-14 20:49 ` [U-Boot] [PATCH v6 75/76] MAINTAINERS: Add myself as SPI NOR maintainer Jagan Teki
2016-02-14 20:49 ` [U-Boot] [PATCH v6 76/76] configs: CONFIG_MTD_SPI_NOR_USE_4K_SECTORS Jagan Teki
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1455482955-19053-12-git-send-email-jteki@openedev.com \
--to=jteki@openedev.com \
--cc=u-boot@lists.denx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox