* [U-Boot] [PATCH 1/8] sf: Add MTD support to spi_flash
@ 2015-10-12 19:54 Jagan Teki
2015-10-12 19:54 ` [U-Boot] [PATCH 2/8] sf: Use mtd_info ops instead of spi_flash ops Jagan Teki
` (7 more replies)
0 siblings, 8 replies; 16+ messages in thread
From: Jagan Teki @ 2015-10-12 19:54 UTC (permalink / raw)
To: u-boot
This patch adds mtd_info support to spi_flash layer, MTD has
proven core for flash operations so adding MTD to spi_flash
will extends more functionality.
Signed-off-by: Jagan Teki <jteki@openedev.com>
---
drivers/mtd/spi/sf_ops.c | 45 +++++++++++++++++++++++++--------------------
drivers/mtd/spi/sf_probe.c | 26 ++++++++++++++++++--------
include/spi_flash.h | 9 +++++----
3 files changed, 48 insertions(+), 32 deletions(-)
diff --git a/drivers/mtd/spi/sf_ops.c b/drivers/mtd/spi/sf_ops.c
index 703099f..f5ee376 100644
--- a/drivers/mtd/spi/sf_ops.c
+++ b/drivers/mtd/spi/sf_ops.c
@@ -146,7 +146,7 @@ static int spi_flash_read_bar(struct spi_flash *flash, u8 idcode0)
u8 curr_bank = 0;
int ret;
- if (flash->size <= SPI_FLASH_16MB_BOUN)
+ if (flash->mtd->size <= SPI_FLASH_16MB_BOUN)
goto bank_end;
switch (idcode0) {
@@ -176,8 +176,8 @@ static void spi_flash_dual(struct spi_flash *flash, u32 *addr)
{
switch (flash->dual_flash) {
case SF_DUAL_STACKED_FLASH:
- if (*addr >= (flash->size >> 1)) {
- *addr -= flash->size >> 1;
+ if (*addr >= (flash->mtd->size >> 1)) {
+ *addr -= flash->mtd->size >> 1;
flash->spi->flags |= SPI_XFER_U_PAGE;
} else {
flash->spi->flags &= ~SPI_XFER_U_PAGE;
@@ -303,7 +303,7 @@ static int spi_flash_cmd_erase_ops(struct spi_flash *flash, u32 offset,
u8 cmd[SPI_FLASH_CMD_LEN];
int ret = -1;
- erase_size = flash->erase_size;
+ erase_size = mtd->erasesize;
if (offset % erase_size || len % erase_size) {
debug("SF: Erase offset/length not multiple of erase size\n");
return -1;
@@ -693,7 +693,7 @@ int spi_flash_decode_fdt(const void *blob, struct spi_flash *flash)
return 0;
}
- if (flash->size != size) {
+ if (flash->mtd->size != size) {
debug("%s: Memory map must cover entire device\n", __func__);
return -1;
}
@@ -705,6 +705,7 @@ int spi_flash_decode_fdt(const void *blob, struct spi_flash *flash)
int spi_flash_scan(struct spi_flash *flash)
{
+ struct mtd_info *mtd = flash->mtd;
const struct spi_flash_params *params;
u16 jedec, ext_jedec;
u8 idcode[5];
@@ -754,24 +755,27 @@ int spi_flash_scan(struct spi_flash *flash)
/* Assign spi data */
flash->name = params->name;
+ mtd->type = MTD_NORFLASH;
+ mtd->writesize = 1;
+ mtd->flags = MTD_CAP_NORFLASH;
flash->memory_map = flash->spi->memory_map;
flash->dual_flash = flash->spi->option;
/* Assign spi_flash ops */
- flash->write = spi_flash_cmd_write_ops;
+ mtd->_write = spi_flash_cmd_write_ops;
#if defined(CONFIG_SPI_FLASH_SST)
if (params->flags & SST_WR)
flash->flags |= SNOR_F_SST_WR;
if (params->flags & SNOR_F_SST_WR) {
if (flash->spi->op_mode_tx & SPI_OPM_TX_BP)
- flash->write = sst_write_bp;
+ mtd->_write = sst_write_bp;
else
- flash->write = sst_write_wp;
+ mtd->_write = sst_write_wp;
}
#endif
- flash->erase = spi_flash_cmd_erase_ops;
- flash->read = spi_flash_cmd_read_ops;
+ mtd->_erase = spi_flash_cmd_erase_ops;
+ mtd->_read = spi_flash_cmd_read_ops;
/* Compute the flash size */
flash->shift = (flash->dual_flash & SF_DUAL_PARALLEL_FLASH) ? 1 : 0;
@@ -790,27 +794,28 @@ int spi_flash_scan(struct spi_flash *flash)
flash->page_size = 256;
}
flash->page_size <<= flash->shift;
+ mtd->writebufsize = flash->page_size;
flash->sector_size = params->sector_size << flash->shift;
- flash->size = flash->sector_size * params->nr_sectors << flash->shift;
+ mtd->size = flash->sector_size * params->nr_sectors << flash->shift;
#ifdef CONFIG_SF_DUAL_FLASH
if (flash->dual_flash & SF_DUAL_STACKED_FLASH)
- flash->size <<= 1;
+ mtd->size <<= 1;
#endif
/* Compute erase sector and command */
if (params->flags & SECT_4K) {
flash->erase_cmd = CMD_ERASE_4K;
- flash->erase_size = 4096 << flash->shift;
+ mtd->erasesize = 4096 << flash->shift;
} else if (params->flags & SECT_32K) {
flash->erase_cmd = CMD_ERASE_32K;
- flash->erase_size = 32768 << flash->shift;
+ mtd->erasesize = 32768 << flash->shift;
} else {
flash->erase_cmd = CMD_ERASE_64K;
- flash->erase_size = flash->sector_size;
+ mtd->erasesize = flash->sector_size;
}
/* Now erase size becomes valid sector size */
- flash->sector_size = flash->erase_size;
+ flash->sector_size = mtd->erasesize;
/* Look for the fastest read cmd */
cmd = fls(params->e_rd_cmd & flash->spi->op_mode_rx);
@@ -882,8 +887,8 @@ int spi_flash_scan(struct spi_flash *flash)
#ifndef CONFIG_SPL_BUILD
printf("SF: Detected %s with page size ", flash->name);
print_size(flash->page_size, ", erase size ");
- print_size(flash->erase_size, ", total ");
- print_size(flash->size, "");
+ print_size(mtd->erasesize, ", total ");
+ print_size(mtd->size, "");
if (flash->memory_map)
printf(", mapped at %p", flash->memory_map);
puts("\n");
@@ -891,9 +896,9 @@ int spi_flash_scan(struct spi_flash *flash)
#ifndef CONFIG_SPI_FLASH_BAR
if (((flash->dual_flash == SF_SINGLE_FLASH) &&
- (flash->size > SPI_FLASH_16MB_BOUN)) ||
+ (mtd->size > SPI_FLASH_16MB_BOUN)) ||
((flash->dual_flash > SF_SINGLE_FLASH) &&
- (flash->size > SPI_FLASH_16MB_BOUN << 1))) {
+ (mtd->size > SPI_FLASH_16MB_BOUN << 1))) {
puts("SF: Warning - Only lower 16MiB accessible,");
puts(" Full access #define CONFIG_SPI_FLASH_BAR\n");
}
diff --git a/drivers/mtd/spi/sf_probe.c b/drivers/mtd/spi/sf_probe.c
index 87ac33e..b8704e2 100644
--- a/drivers/mtd/spi/sf_probe.c
+++ b/drivers/mtd/spi/sf_probe.c
@@ -14,9 +14,15 @@
#include <malloc.h>
#include <spi.h>
#include <spi_flash.h>
+#include <linux/mtd/mtd.h>
#include "sf_internal.h"
+struct spi_flash_priv {
+ struct spi_flash flash;
+ struct mtd_info mtd;
+};
+
#ifndef CONFIG_DM_SPI_FLASH
struct spi_flash *spi_flash_probe_tail(struct spi_slave *bus)
{
@@ -123,12 +129,19 @@ int spi_flash_std_erase(struct udevice *dev, u32 offset, size_t len)
int spi_flash_std_probe(struct udevice *dev)
{
- struct spi_flash *flash = dev_get_uclass_priv(dev);
+ struct spi_flash_priv *priv = dev_get_uclass_priv(dev);
struct spi_slave *slave = dev_get_parentdata(dev);
+ struct spi_flash *flash;
int ret;
- flash->dev = dev;
+ flash = &priv->flash;
+ flash->mtd = &priv->mtd;
+
flash->spi = slave;
+ flash->priv = priv;
+
+ priv->mtd.priv = flash;
+ flash->dev = dev;
/* Claim spi bus */
ret = spi_claim_bus(slave);
@@ -143,19 +156,16 @@ int spi_flash_std_probe(struct udevice *dev)
goto err_scan;
}
-#ifdef CONFIG_SPI_FLASH_MTD
- ret = spi_flash_mtd_register(flash);
+ ret = add_mtd_device(&priv->mtd);
if (ret) {
printf("SF: failed to register mtd device: %d\n", ret);
goto err_mtd;
}
-#endif
+
return ret;
-#ifdef CONFIG_SPI_FLASH_MTD
err_mtd:
spi_free_slave(slave);
-#endif
err_scan:
spi_release_bus(slave);
return ret;
@@ -177,7 +187,7 @@ U_BOOT_DRIVER(spi_flash_std) = {
.id = UCLASS_SPI_FLASH,
.of_match = spi_flash_std_ids,
.probe = spi_flash_std_probe,
- .priv_auto_alloc_size = sizeof(struct spi_flash),
+ .priv_auto_alloc_size = sizeof(struct spi_flash_priv),
.ops = &spi_flash_std_ops,
};
diff --git a/include/spi_flash.h b/include/spi_flash.h
index 0732172..d0af8d3 100644
--- a/include/spi_flash.h
+++ b/include/spi_flash.h
@@ -17,6 +17,7 @@
#include <dm.h> /* Because we dereference struct udevice here */
#include <linux/types.h>
+#include <linux/mtd/mtd.h>
#ifndef CONFIG_SF_DEFAULT_SPEED
# define CONFIG_SF_DEFAULT_SPEED 1000000
@@ -36,16 +37,15 @@ struct spi_slave;
/**
* struct spi_flash - SPI flash structure
*
+ * @mtd: point to a mtd_info structure
* @spi: SPI slave
* @dev: SPI flash device
* @name: Name of SPI flash
* @dual_flash: Indicates dual flash memories - dual stacked, parallel
* @shift: Flash shift useful in dual parallel
* @flags: Indication of spi flash flags
- * @size: Total flash size
* @page_size: Write (page) size
* @sector_size: Sector size
- * @erase_size: Erase size
* @bank_read_cmd: Bank read cmd
* @bank_write_cmd: Bank write cmd
* @bank_curr: Current flash bank
@@ -54,6 +54,7 @@ struct spi_slave;
* @write_cmd: Write cmd - page and quad program.
* @dummy_byte: Dummy cycles for read operation.
* @memory_map: Address of read-only SPI flash access
+ * @priv: the private data
* @read: Flash read ops: Read len bytes at offset into buf
* Supported cmds: Fast Array Read
* @write: Flash write ops: Write len bytes from buf into offset
@@ -63,6 +64,7 @@ struct spi_slave;
* return 0 - Success, 1 - Failure
*/
struct spi_flash {
+ struct mtd_info *mtd;
struct spi_slave *spi;
#ifdef CONFIG_DM_SPI_FLASH
struct udevice *dev;
@@ -72,10 +74,8 @@ struct spi_flash {
u8 shift;
u16 flags;
- u32 size;
u32 page_size;
u32 sector_size;
- u32 erase_size;
#ifdef CONFIG_SPI_FLASH_BAR
u8 bank_read_cmd;
u8 bank_write_cmd;
@@ -87,6 +87,7 @@ struct spi_flash {
u8 dummy_byte;
void *memory_map;
+ void *priv;
int (*read)(struct spi_flash *flash, u32 offset, size_t len, void *buf);
int (*write)(struct spi_flash *flash, u32 offset, size_t len,
const void *buf);
--
1.9.1
^ permalink raw reply related [flat|nested] 16+ messages in thread
* [U-Boot] [PATCH 2/8] sf: Use mtd_info ops instead of spi_flash ops
2015-10-12 19:54 [U-Boot] [PATCH 1/8] sf: Add MTD support to spi_flash Jagan Teki
@ 2015-10-12 19:54 ` Jagan Teki
2015-10-29 6:29 ` Heiko Schocher
2015-10-12 19:54 ` [U-Boot] [PATCH 3/8] cmd_sf: Use mtd->size instead of flash->size Jagan Teki
` (6 subsequent siblings)
7 siblings, 1 reply; 16+ messages in thread
From: Jagan Teki @ 2015-10-12 19:54 UTC (permalink / raw)
To: u-boot
Since MTD support is added in spi_flash layer, this patch uses
mtd_info operations instead of legacy spi_flash operations.
Signed-off-by: Jagan Teki <jteki@openedev.com>
---
drivers/mtd/spi/sf_ops.c | 66 ++++++++++++++++++++++++++++--------------------
include/spi_flash.h | 24 ++++++++----------
2 files changed, 49 insertions(+), 41 deletions(-)
diff --git a/drivers/mtd/spi/sf_ops.c b/drivers/mtd/spi/sf_ops.c
index f5ee376..d10ca45 100644
--- a/drivers/mtd/spi/sf_ops.c
+++ b/drivers/mtd/spi/sf_ops.c
@@ -296,18 +296,16 @@ int spi_flash_write_common(struct spi_flash *flash, const u8 *cmd,
return ret;
}
-static int spi_flash_cmd_erase_ops(struct spi_flash *flash, u32 offset,
- size_t len)
+static int spi_flash_cmd_erase_ops(struct mtd_info *mtd,
+ struct erase_info *instr)
{
- u32 erase_size, erase_addr;
+ struct spi_flash *flash = mtd->priv;
+ u32 offset, len, erase_addr;
u8 cmd[SPI_FLASH_CMD_LEN];
int ret = -1;
- erase_size = mtd->erasesize;
- if (offset % erase_size || len % erase_size) {
- debug("SF: Erase offset/length not multiple of erase size\n");
- return -1;
- }
+ offset = instr->addr;
+ len = instr->len;
cmd[0] = flash->erase_cmd;
while (len) {
@@ -330,19 +328,24 @@ static int spi_flash_cmd_erase_ops(struct spi_flash *flash, u32 offset,
ret = spi_flash_write_common(flash, cmd, sizeof(cmd), NULL, 0);
if (ret < 0) {
debug("SF: erase failed\n");
- break;
+ goto erase_err;
}
- offset += erase_size;
- len -= erase_size;
+ offset += mtd->erasesize;
+ len -= mtd->erasesize;
}
return ret;
+
+erase_err:
+ instr->state = MTD_ERASE_FAILED;
+ return ret;
}
-static int spi_flash_cmd_write_ops(struct spi_flash *flash, u32 offset,
- size_t len, const void *buf)
+static int spi_flash_cmd_write_ops(struct mtd_info *mtd, loff_t offset,
+ size_t len, size_t *retlen, const u_char *buf)
{
+ struct spi_flash *flash = mtd->priv;
unsigned long byte_addr, page_size;
u32 write_addr;
size_t chunk_len, actual;
@@ -384,6 +387,7 @@ static int spi_flash_cmd_write_ops(struct spi_flash *flash, u32 offset,
}
offset += chunk_len;
+ *retlen += chunk_len;
}
return ret;
@@ -417,11 +421,12 @@ void __weak spi_flash_copy_mmap(void *data, void *offset, size_t len)
memcpy(data, offset, len);
}
-static int spi_flash_cmd_read_ops(struct spi_flash *flash, u32 offset,
- size_t len, void *data)
+static int spi_flash_cmd_read_ops(struct mtd_info *mtd, loff_t offset,
+ size_t len, size_t *retlen, u_char *data)
{
- u8 *cmd, cmdsz;
+ struct spi_flash *flash = mtd->priv;
u32 remain_len, read_len, read_addr;
+ u8 *cmd, cmdsz;
int bank_sel = 0;
int ret = -1;
@@ -478,6 +483,7 @@ static int spi_flash_cmd_read_ops(struct spi_flash *flash, u32 offset,
offset += read_len;
len -= read_len;
data += read_len;
+ *retlen += read_len;
}
free(cmd);
@@ -485,7 +491,8 @@ static int spi_flash_cmd_read_ops(struct spi_flash *flash, u32 offset,
}
#ifdef CONFIG_SPI_FLASH_SST
-static int sst_byte_write(struct spi_flash *flash, u32 offset, const void *buf)
+static int sst_byte_write(struct spi_flash *flash, u32 offset,
+ const void *buf, size_t *retlen)
{
int ret;
u8 cmd[4] = {
@@ -506,12 +513,15 @@ static int sst_byte_write(struct spi_flash *flash, u32 offset, const void *buf)
if (ret)
return ret;
+ *retlen += 1;
+
return spi_flash_cmd_wait_ready(flash, SPI_FLASH_PROG_TIMEOUT);
}
-static int sst_write_wp(struct spi_flash *flash, u32 offset, size_t len,
- const void *buf)
+static int sst_write_wp(struct mtd_info *mtd, loff_t offset, size_t len,
+ size_t *retlen, const u_char *buf)
{
+ struct spi_flash *flash = mtd->priv;
size_t actual, cmd_len;
int ret;
u8 cmd[4];
@@ -525,7 +535,7 @@ static int sst_write_wp(struct spi_flash *flash, u32 offset, size_t len,
/* If the data is not word aligned, write out leading single byte */
actual = offset % 2;
if (actual) {
- ret = sst_byte_write(flash, offset, buf);
+ ret = sst_byte_write(flash, offset, buf, retlen);
if (ret)
goto done;
}
@@ -542,7 +552,7 @@ static int sst_write_wp(struct spi_flash *flash, u32 offset, size_t len,
cmd[3] = offset;
for (; actual < len - 1; actual += 2) {
- debug("WP[%02x]: 0x%p => cmd = { 0x%02x 0x%06x }\n",
+ debug("WP[%02x]: 0x%p => cmd = { 0x%02x 0x%06llx }\n",
spi_w8r8(flash->spi, CMD_READ_STATUS), buf + actual,
cmd[0], offset);
@@ -559,6 +569,7 @@ static int sst_write_wp(struct spi_flash *flash, u32 offset, size_t len,
cmd_len = 1;
offset += 2;
+ *retlen += 2;
}
if (!ret)
@@ -566,19 +577,20 @@ static int sst_write_wp(struct spi_flash *flash, u32 offset, size_t len,
/* If there is a single trailing byte, write it out */
if (!ret && actual != len)
- ret = sst_byte_write(flash, offset, buf + actual);
+ ret = sst_byte_write(flash, offset, buf + actual, retlen);
done:
- debug("SF: sst: program %s %zu bytes @ 0x%zx\n",
+ debug("SF: sst: program %s %zu bytes @ 0x%llx\n",
ret ? "failure" : "success", len, offset - actual);
spi_release_bus(flash->spi);
return ret;
}
-static int sst_write_bp(struct spi_flash *flash, u32 offset, size_t len,
- const void *buf)
+static int sst_write_bp(struct mtd_info *mtd, loff_t offset, size_t len,
+ size_t *retlen, const u_char *buf)
{
+ struct spi_flash *flash = mtd->priv;
size_t actual;
int ret;
@@ -589,7 +601,7 @@ static int sst_write_bp(struct spi_flash *flash, u32 offset, size_t len,
}
for (actual = 0; actual < len; actual++) {
- ret = sst_byte_write(flash, offset, buf + actual);
+ ret = sst_byte_write(flash, offset, buf + actual, retlen);
if (ret) {
debug("SF: sst byte program failed\n");
break;
@@ -600,7 +612,7 @@ static int sst_write_bp(struct spi_flash *flash, u32 offset, size_t len,
if (!ret)
ret = spi_flash_cmd_write_disable(flash);
- debug("SF: sst: program %s %zu bytes @ 0x%zx\n",
+ debug("SF: sst: program %s %zu bytes @ 0x%llx\n",
ret ? "failure" : "success", len, offset - actual);
spi_release_bus(flash->spi);
diff --git a/include/spi_flash.h b/include/spi_flash.h
index d0af8d3..fe03b8d 100644
--- a/include/spi_flash.h
+++ b/include/spi_flash.h
@@ -55,13 +55,6 @@ struct spi_slave;
* @dummy_byte: Dummy cycles for read operation.
* @memory_map: Address of read-only SPI flash access
* @priv: the private data
- * @read: Flash read ops: Read len bytes at offset into buf
- * Supported cmds: Fast Array Read
- * @write: Flash write ops: Write len bytes from buf into offset
- * Supported cmds: Page Program
- * @erase: Flash erase ops: Erase len bytes from offset
- * Supported cmds: Sector erase 4K, 32K, 64K
- * return 0 - Success, 1 - Failure
*/
struct spi_flash {
struct mtd_info *mtd;
@@ -88,10 +81,6 @@ struct spi_flash {
void *memory_map;
void *priv;
- int (*read)(struct spi_flash *flash, u32 offset, size_t len, void *buf);
- int (*write)(struct spi_flash *flash, u32 offset, size_t len,
- const void *buf);
- int (*erase)(struct spi_flash *flash, u32 offset, size_t len);
};
struct dm_spi_flash_ops {
@@ -156,19 +145,26 @@ int spi_flash_remove(struct udevice *flash);
static inline int spi_flash_read(struct spi_flash *flash, u32 offset,
size_t len, void *buf)
{
- return spi_flash_read_dm(flash->dev, offset, len, buf);
+ return mtd_read(flash->mtd, offset, len, &len, (u_char *)buf);
}
static inline int spi_flash_write(struct spi_flash *flash, u32 offset,
size_t len, const void *buf)
{
- return spi_flash_write_dm(flash->dev, offset, len, buf);
+ return mtd_write(flash->mtd, offset, len, &len, (u_char *)buf);
}
static inline int spi_flash_erase(struct spi_flash *flash, u32 offset,
size_t len)
{
- return spi_flash_erase_dm(flash->dev, offset, len);
+ struct erase_info instr;
+
+ instr.mtd = flash->mtd;
+ instr.addr = offset;
+ instr.len = len;
+ instr.callback = 0;
+
+ return mtd_erase(flash->mtd, &instr);
}
struct sandbox_state;
--
1.9.1
^ permalink raw reply related [flat|nested] 16+ messages in thread
* [U-Boot] [PATCH 3/8] cmd_sf: Use mtd->size instead of flash->size
2015-10-12 19:54 [U-Boot] [PATCH 1/8] sf: Add MTD support to spi_flash Jagan Teki
2015-10-12 19:54 ` [U-Boot] [PATCH 2/8] sf: Use mtd_info ops instead of spi_flash ops Jagan Teki
@ 2015-10-12 19:54 ` Jagan Teki
2015-10-29 6:32 ` Heiko Schocher
2015-10-12 19:54 ` [U-Boot] [PATCH 4/8] dm-sf: use mtd_ops, drop dm_spi_flash_ops Jagan Teki
` (5 subsequent siblings)
7 siblings, 1 reply; 16+ messages in thread
From: Jagan Teki @ 2015-10-12 19:54 UTC (permalink / raw)
To: u-boot
Since mtd got added, replace flash->size with mtd->size.
Signed-off-by: Jagan Teki <jteki@openedev.com>
---
common/cmd_sf.c | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/common/cmd_sf.c b/common/cmd_sf.c
index ac7f5df..a501376 100644
--- a/common/cmd_sf.c
+++ b/common/cmd_sf.c
@@ -275,13 +275,13 @@ static int do_spi_flash_read_write(int argc, char * const argv[])
return -1;
if (mtd_arg_off_size(argc - 2, &argv[2], &dev, &offset, &len,
- &maxsize, MTD_DEV_TYPE_NOR, flash->size))
+ &maxsize, MTD_DEV_TYPE_NOR, flash->mtd->size))
return -1;
/* Consistency checking */
- if (offset + len > flash->size) {
- printf("ERROR: attempting %s past flash size (%#x)\n",
- argv[0], flash->size);
+ if (offset + len > flash->mtd->size) {
+ printf("ERROR: attempting %s past flash size (0x%llx)\n",
+ argv[0], flash->mtd->size);
return 1;
}
@@ -327,7 +327,7 @@ static int do_spi_flash_erase(int argc, char * const argv[])
return -1;
if (mtd_arg_off(argv[1], &dev, &offset, &len, &maxsize,
- MTD_DEV_TYPE_NOR, flash->size))
+ MTD_DEV_TYPE_NOR, flash->mtd->size))
return -1;
ret = sf_parse_len_arg(argv[2], &size);
@@ -335,9 +335,9 @@ static int do_spi_flash_erase(int argc, char * const argv[])
return -1;
/* Consistency checking */
- if (offset + size > flash->size) {
- printf("ERROR: attempting %s past flash size (%#x)\n",
- argv[0], flash->size);
+ if (offset + size > flash->mtd->size) {
+ printf("ERROR: attempting %s past flash size (0x%llx)\n",
+ argv[0], flash->mtd->size);
return 1;
}
--
1.9.1
^ permalink raw reply related [flat|nested] 16+ messages in thread
* [U-Boot] [PATCH 4/8] dm-sf: use mtd_ops, drop dm_spi_flash_ops
2015-10-12 19:54 [U-Boot] [PATCH 1/8] sf: Add MTD support to spi_flash Jagan Teki
2015-10-12 19:54 ` [U-Boot] [PATCH 2/8] sf: Use mtd_info ops instead of spi_flash ops Jagan Teki
2015-10-12 19:54 ` [U-Boot] [PATCH 3/8] cmd_sf: Use mtd->size instead of flash->size Jagan Teki
@ 2015-10-12 19:54 ` Jagan Teki
2015-10-29 6:35 ` Heiko Schocher
2015-10-12 19:54 ` [U-Boot] [PATCH 5/8] sf: Add MTD support for non-dm spi_flash interface Jagan Teki
` (4 subsequent siblings)
7 siblings, 1 reply; 16+ messages in thread
From: Jagan Teki @ 2015-10-12 19:54 UTC (permalink / raw)
To: u-boot
Since mtd_info ops got introduced, just drop the unneeded
dm_spi_flash operations.
Signed-off-by: Jagan Teki <jteki@openedev.com>
---
drivers/mtd/spi/sf-uclass.c | 16 --------
drivers/mtd/spi/sf_probe.c | 30 ---------------
include/spi_flash.h | 91 +++++++--------------------------------------
3 files changed, 14 insertions(+), 123 deletions(-)
diff --git a/drivers/mtd/spi/sf-uclass.c b/drivers/mtd/spi/sf-uclass.c
index 350e21a..5cdbd1b 100644
--- a/drivers/mtd/spi/sf-uclass.c
+++ b/drivers/mtd/spi/sf-uclass.c
@@ -11,22 +11,6 @@
#include <dm/device-internal.h>
#include "sf_internal.h"
-int spi_flash_read_dm(struct udevice *dev, u32 offset, size_t len, void *buf)
-{
- return sf_get_ops(dev)->read(dev, offset, len, buf);
-}
-
-int spi_flash_write_dm(struct udevice *dev, u32 offset, size_t len,
- const void *buf)
-{
- return sf_get_ops(dev)->write(dev, offset, len, buf);
-}
-
-int spi_flash_erase_dm(struct udevice *dev, u32 offset, size_t len)
-{
- return sf_get_ops(dev)->erase(dev, offset, len);
-}
-
/*
* TODO(sjg at chromium.org): This is an old-style function. We should remove
* it when all SPI flash drivers use dm
diff --git a/drivers/mtd/spi/sf_probe.c b/drivers/mtd/spi/sf_probe.c
index b8704e2..5e314e2 100644
--- a/drivers/mtd/spi/sf_probe.c
+++ b/drivers/mtd/spi/sf_probe.c
@@ -104,29 +104,6 @@ void spi_flash_free(struct spi_flash *flash)
#else /* defined CONFIG_DM_SPI_FLASH */
-static int spi_flash_std_read(struct udevice *dev, u32 offset, size_t len,
- void *buf)
-{
- struct spi_flash *flash = dev_get_uclass_priv(dev);
-
- return flash->read(flash, offset, len, buf);
-}
-
-int spi_flash_std_write(struct udevice *dev, u32 offset, size_t len,
- const void *buf)
-{
- struct spi_flash *flash = dev_get_uclass_priv(dev);
-
- return flash->write(flash, offset, len, buf);
-}
-
-int spi_flash_std_erase(struct udevice *dev, u32 offset, size_t len)
-{
- struct spi_flash *flash = dev_get_uclass_priv(dev);
-
- return flash->erase(flash, offset, len);
-}
-
int spi_flash_std_probe(struct udevice *dev)
{
struct spi_flash_priv *priv = dev_get_uclass_priv(dev);
@@ -171,12 +148,6 @@ err_scan:
return ret;
}
-static const struct dm_spi_flash_ops spi_flash_std_ops = {
- .read = spi_flash_std_read,
- .write = spi_flash_std_write,
- .erase = spi_flash_std_erase,
-};
-
static const struct udevice_id spi_flash_std_ids[] = {
{ .compatible = "spi-flash" },
{ }
@@ -188,7 +159,6 @@ U_BOOT_DRIVER(spi_flash_std) = {
.of_match = spi_flash_std_ids,
.probe = spi_flash_std_probe,
.priv_auto_alloc_size = sizeof(struct spi_flash_priv),
- .ops = &spi_flash_std_ops,
};
#endif /* CONFIG_DM_SPI_FLASH */
diff --git a/include/spi_flash.h b/include/spi_flash.h
index fe03b8d..8dd000d 100644
--- a/include/spi_flash.h
+++ b/include/spi_flash.h
@@ -83,52 +83,7 @@ struct spi_flash {
void *priv;
};
-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,
- const void *buf);
- int (*erase)(struct udevice *dev, u32 offset, size_t len);
-};
-
-/* Access the serial operations for a device */
-#define sf_get_ops(dev) ((struct dm_spi_flash_ops *)(dev)->driver->ops)
-
#ifdef CONFIG_DM_SPI_FLASH
-/**
- * spi_flash_read_dm() - Read data from SPI flash
- *
- * @dev: SPI flash device
- * @offset: Offset into device in bytes to read from
- * @len: Number of bytes to read
- * @buf: Buffer to put the data that is read
- * @return 0 if OK, -ve on error
- */
-int spi_flash_read_dm(struct udevice *dev, u32 offset, size_t len, void *buf);
-
-/**
- * spi_flash_write_dm() - Write data to SPI flash
- *
- * @dev: SPI flash device
- * @offset: Offset into device in bytes to write to
- * @len: Number of bytes to write
- * @buf: Buffer containing bytes to write
- * @return 0 if OK, -ve on error
- */
-int spi_flash_write_dm(struct udevice *dev, u32 offset, size_t len,
- const void *buf);
-
-/**
- * spi_flash_erase_dm() - Erase blocks of the SPI flash
- *
- * Note that @len must be a muiltiple of the flash sector size.
- *
- * @dev: SPI flash device
- * @offset: Offset into device in bytes to start erasing
- * @len: Number of bytes to erase
- * @return 0 if OK, -ve on error
- */
-int spi_flash_erase_dm(struct udevice *dev, u32 offset, size_t len);
-
int spi_flash_probe_bus_cs(unsigned int busnum, unsigned int cs,
unsigned int max_hz, unsigned int spi_mode,
struct udevice **devp);
@@ -142,31 +97,6 @@ void spi_flash_free(struct spi_flash *flash);
int spi_flash_remove(struct udevice *flash);
-static inline int spi_flash_read(struct spi_flash *flash, u32 offset,
- size_t len, void *buf)
-{
- return mtd_read(flash->mtd, offset, len, &len, (u_char *)buf);
-}
-
-static inline int spi_flash_write(struct spi_flash *flash, u32 offset,
- size_t len, const void *buf)
-{
- return mtd_write(flash->mtd, offset, len, &len, (u_char *)buf);
-}
-
-static inline int spi_flash_erase(struct spi_flash *flash, u32 offset,
- size_t len)
-{
- struct erase_info instr;
-
- instr.mtd = flash->mtd;
- instr.addr = offset;
- instr.len = len;
- instr.callback = 0;
-
- return mtd_erase(flash->mtd, &instr);
-}
-
struct sandbox_state;
int sandbox_sf_bind_emul(struct sandbox_state *state, int busnum, int cs,
@@ -191,25 +121,32 @@ struct spi_flash *spi_flash_probe_fdt(const void *blob, int slave_node,
int spi_node);
void spi_flash_free(struct spi_flash *flash);
+#endif
static inline int spi_flash_read(struct spi_flash *flash, u32 offset,
- size_t len, void *buf)
+ size_t len, void *buf)
{
- return flash->read(flash, offset, len, buf);
+ return mtd_read(flash->mtd, offset, len, &len, (u_char *)buf);
}
static inline int spi_flash_write(struct spi_flash *flash, u32 offset,
- size_t len, const void *buf)
+ size_t len, const void *buf)
{
- return flash->write(flash, offset, len, buf);
+ return mtd_write(flash->mtd, offset, len, &len, (u_char *)buf);
}
static inline int spi_flash_erase(struct spi_flash *flash, u32 offset,
- size_t len)
+ size_t len)
{
- return flash->erase(flash, offset, len);
+ struct erase_info instr;
+
+ instr.mtd = flash->mtd;
+ instr.addr = offset;
+ instr.len = len;
+ instr.callback = 0;
+
+ return mtd_erase(flash->mtd, &instr);
}
-#endif
void spi_boot(void) __noreturn;
void spi_spl_load_image(uint32_t offs, unsigned int size, void *vdst);
--
1.9.1
^ permalink raw reply related [flat|nested] 16+ messages in thread
* [U-Boot] [PATCH 5/8] sf: Add MTD support for non-dm spi_flash interface
2015-10-12 19:54 [U-Boot] [PATCH 1/8] sf: Add MTD support to spi_flash Jagan Teki
` (2 preceding siblings ...)
2015-10-12 19:54 ` [U-Boot] [PATCH 4/8] dm-sf: use mtd_ops, drop dm_spi_flash_ops Jagan Teki
@ 2015-10-12 19:54 ` Jagan Teki
2015-10-29 6:37 ` Heiko Schocher
2015-10-12 19:54 ` [U-Boot] [PATCH 6/8] sf: probe: Minor cleanup Jagan Teki
` (3 subsequent siblings)
7 siblings, 1 reply; 16+ messages in thread
From: Jagan Teki @ 2015-10-12 19:54 UTC (permalink / raw)
To: u-boot
This patch adds MTD support to non-dm spi_flash
interface code.
Signed-off-by: Jagan Teki <jteki@openedev.com>
---
drivers/mtd/spi/sf_probe.c | 26 ++++++++++++++------------
1 file changed, 14 insertions(+), 12 deletions(-)
diff --git a/drivers/mtd/spi/sf_probe.c b/drivers/mtd/spi/sf_probe.c
index 5e314e2..60abaf2 100644
--- a/drivers/mtd/spi/sf_probe.c
+++ b/drivers/mtd/spi/sf_probe.c
@@ -26,17 +26,24 @@ struct spi_flash_priv {
#ifndef CONFIG_DM_SPI_FLASH
struct spi_flash *spi_flash_probe_tail(struct spi_slave *bus)
{
+ struct spi_flash_priv *priv;
struct spi_flash *flash;
int ret;
- /* Allocate space if needed (not used by sf-uclass */
- flash = calloc(1, sizeof(*flash));
- if (!flash) {
- debug("SF: Failed to allocate spi_flash\n");
+ /* Allocate space if needed (not used by sf-uclass) */
+ priv = calloc(1, sizeof(*priv));
+ if (!priv) {
+ debug("SF: Failed to allocate spi_flash_priv\n");
return NULL;
}
+ flash = &priv->flash;
+ flash->mtd = &priv->mtd;
+
flash->spi = bus;
+ flash->priv = priv;
+
+ priv->mtd.priv = flash;
/* Claim spi bus */
ret = spi_claim_bus(bus);
@@ -49,19 +56,16 @@ struct spi_flash *spi_flash_probe_tail(struct spi_slave *bus)
if (ret)
goto err_scan;
-#ifdef CONFIG_SPI_FLASH_MTD
- ret = spi_flash_mtd_register(flash);
+ ret = add_mtd_device(&priv->mtd);
if (ret) {
printf("SF: failed to register mtd device: %d\n", ret);
goto err_mtd;
}
-#endif
+
return flash;
-#ifdef CONFIG_SPI_FLASH_MTD
err_mtd:
spi_free_slave(bus);
-#endif
err_scan:
spi_release_bus(bus);
err_claim:
@@ -95,9 +99,7 @@ struct spi_flash *spi_flash_probe_fdt(const void *blob, int slave_node,
void spi_flash_free(struct spi_flash *flash)
{
-#ifdef CONFIG_SPI_FLASH_MTD
- spi_flash_mtd_unregister();
-#endif
+ del_mtd_device(flash->mtd);
spi_free_slave(flash->spi);
free(flash);
}
--
1.9.1
^ permalink raw reply related [flat|nested] 16+ messages in thread
* [U-Boot] [PATCH 6/8] sf: probe: Minor cleanup
2015-10-12 19:54 [U-Boot] [PATCH 1/8] sf: Add MTD support to spi_flash Jagan Teki
` (3 preceding siblings ...)
2015-10-12 19:54 ` [U-Boot] [PATCH 5/8] sf: Add MTD support for non-dm spi_flash interface Jagan Teki
@ 2015-10-12 19:54 ` Jagan Teki
2015-10-29 6:54 ` Heiko Schocher
2015-10-12 19:54 ` [U-Boot] [PATCH 7/8] sf: Drop SPI_FLASH_MTD driver Jagan Teki
` (2 subsequent siblings)
7 siblings, 1 reply; 16+ messages in thread
From: Jagan Teki @ 2015-10-12 19:54 UTC (permalink / raw)
To: u-boot
- Use static for file-scope function
- Remove unneeded header file
- Use spi instead of slave notation for spi_slave {}
Signed-off-by: Jagan Teki <jteki@openedev.com>
---
drivers/mtd/spi/sf_probe.c | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/drivers/mtd/spi/sf_probe.c b/drivers/mtd/spi/sf_probe.c
index 60abaf2..112ab27 100644
--- a/drivers/mtd/spi/sf_probe.c
+++ b/drivers/mtd/spi/sf_probe.c
@@ -24,7 +24,7 @@ struct spi_flash_priv {
};
#ifndef CONFIG_DM_SPI_FLASH
-struct spi_flash *spi_flash_probe_tail(struct spi_slave *bus)
+static struct spi_flash *spi_flash_probe_tail(struct spi_slave *bus)
{
struct spi_flash_priv *priv;
struct spi_flash *flash;
@@ -106,24 +106,24 @@ void spi_flash_free(struct spi_flash *flash)
#else /* defined CONFIG_DM_SPI_FLASH */
-int spi_flash_std_probe(struct udevice *dev)
+static int spi_flash_std_probe(struct udevice *dev)
{
struct spi_flash_priv *priv = dev_get_uclass_priv(dev);
- struct spi_slave *slave = dev_get_parentdata(dev);
+ struct spi_slave *spi = dev_get_parentdata(dev);
struct spi_flash *flash;
int ret;
flash = &priv->flash;
flash->mtd = &priv->mtd;
- flash->spi = slave;
+ flash->spi = spi;
flash->priv = priv;
priv->mtd.priv = flash;
flash->dev = dev;
/* Claim spi bus */
- ret = spi_claim_bus(slave);
+ ret = spi_claim_bus(spi);
if (ret) {
debug("SF: Failed to claim SPI bus: %d\n", ret);
return ret;
@@ -144,9 +144,9 @@ int spi_flash_std_probe(struct udevice *dev)
return ret;
err_mtd:
- spi_free_slave(slave);
+ spi_free_slave(spi);
err_scan:
- spi_release_bus(slave);
+ spi_release_bus(spi);
return ret;
}
--
1.9.1
^ permalink raw reply related [flat|nested] 16+ messages in thread
* [U-Boot] [PATCH 7/8] sf: Drop SPI_FLASH_MTD driver
2015-10-12 19:54 [U-Boot] [PATCH 1/8] sf: Add MTD support to spi_flash Jagan Teki
` (4 preceding siblings ...)
2015-10-12 19:54 ` [U-Boot] [PATCH 6/8] sf: probe: Minor cleanup Jagan Teki
@ 2015-10-12 19:54 ` Jagan Teki
2015-10-12 19:54 ` [U-Boot] [PATCH 8/8] configs: Remove CONFIG_SPI_FLASH_MTD Jagan Teki
2015-10-29 6:04 ` [U-Boot] [PATCH 1/8] sf: Add MTD support to spi_flash Heiko Schocher
7 siblings, 0 replies; 16+ messages in thread
From: Jagan Teki @ 2015-10-12 19:54 UTC (permalink / raw)
To: u-boot
Now MTD core has been added as part of spi-flash layer,
so there is no need for explicit driver for handling
mtd stuff, hence removed all neccessary code regarding
SPI_FLASH_MTD driver.
Signed-off-by: Jagan Teki <jteki@openedev.com>
Cc: Daniel Schwierzeck <daniel.schwierzeck@gmail.com>
Cc: Heiko Schocher <hs@denx.de>
---
drivers/mtd/spi/Kconfig | 12 -----
drivers/mtd/spi/Makefile | 1 -
drivers/mtd/spi/sf_internal.h | 5 --
drivers/mtd/spi/sf_mtd.c | 104 ------------------------------------------
4 files changed, 122 deletions(-)
delete mode 100644 drivers/mtd/spi/sf_mtd.c
diff --git a/drivers/mtd/spi/Kconfig b/drivers/mtd/spi/Kconfig
index 3f7433c..78932a4 100644
--- a/drivers/mtd/spi/Kconfig
+++ b/drivers/mtd/spi/Kconfig
@@ -116,16 +116,4 @@ config SPI_FLASH_DATAFLASH
If unsure, say N
-config SPI_FLASH_MTD
- bool "SPI Flash MTD support"
- depends on SPI_FLASH
- help
- Enable the MTD support for spi flash layer, this adapter is for
- translating mtd_read/mtd_write commands into spi_flash_read/write
- commands. It is not intended to use it within sf_cmd or the SPI
- flash subsystem. Such an adapter is needed for subsystems like
- UBI which can only operate on top of the MTD layer.
-
- If unsure, say N
-
endmenu # menu "SPI Flash Support"
diff --git a/drivers/mtd/spi/Makefile b/drivers/mtd/spi/Makefile
index 66c4424..1824261 100644
--- a/drivers/mtd/spi/Makefile
+++ b/drivers/mtd/spi/Makefile
@@ -14,6 +14,5 @@ endif
obj-$(CONFIG_SPI_FLASH) += sf_probe.o sf_ops.o sf_params.o sf.o
obj-$(CONFIG_SPI_FLASH_DATAFLASH) += sf_dataflash.o
-obj-$(CONFIG_SPI_FLASH_MTD) += sf_mtd.o
obj-$(CONFIG_SPI_FLASH_SANDBOX) += sandbox.o
obj-$(CONFIG_SPI_M95XXX) += eeprom_m95xxx.o
diff --git a/drivers/mtd/spi/sf_internal.h b/drivers/mtd/spi/sf_internal.h
index d74bc18..84afddf 100644
--- a/drivers/mtd/spi/sf_internal.h
+++ b/drivers/mtd/spi/sf_internal.h
@@ -191,11 +191,6 @@ int spi_flash_write_common(struct spi_flash *flash, const u8 *cmd,
int spi_flash_read_common(struct spi_flash *flash, const u8 *cmd,
size_t cmd_len, void *data, size_t data_len);
-#ifdef CONFIG_SPI_FLASH_MTD
-int spi_flash_mtd_register(struct spi_flash *flash);
-void spi_flash_mtd_unregister(void);
-#endif
-
/**
* spi_flash_scan - scan the SPI FLASH
* @flash: the spi flash structure
diff --git a/drivers/mtd/spi/sf_mtd.c b/drivers/mtd/spi/sf_mtd.c
deleted file mode 100644
index 0b9cb62..0000000
--- a/drivers/mtd/spi/sf_mtd.c
+++ /dev/null
@@ -1,104 +0,0 @@
-/*
- * Copyright (C) 2012-2014 Daniel Schwierzeck, daniel.schwierzeck at gmail.com
- *
- * SPDX-License-Identifier: GPL-2.0+
- */
-
-#include <common.h>
-#include <malloc.h>
-#include <asm/errno.h>
-#include <linux/mtd/mtd.h>
-#include <spi_flash.h>
-
-static struct mtd_info sf_mtd_info;
-static char sf_mtd_name[8];
-
-static int spi_flash_mtd_erase(struct mtd_info *mtd, struct erase_info *instr)
-{
- struct spi_flash *flash = mtd->priv;
- int err;
-
- instr->state = MTD_ERASING;
-
- err = spi_flash_erase(flash, instr->addr, instr->len);
- if (err) {
- instr->state = MTD_ERASE_FAILED;
- instr->fail_addr = MTD_FAIL_ADDR_UNKNOWN;
- return -EIO;
- }
-
- instr->state = MTD_ERASE_DONE;
- mtd_erase_callback(instr);
-
- return 0;
-}
-
-static int spi_flash_mtd_read(struct mtd_info *mtd, loff_t from, size_t len,
- size_t *retlen, u_char *buf)
-{
- struct spi_flash *flash = mtd->priv;
- int err;
-
- err = spi_flash_read(flash, from, len, buf);
- if (!err)
- *retlen = len;
-
- return err;
-}
-
-static int spi_flash_mtd_write(struct mtd_info *mtd, loff_t to, size_t len,
- size_t *retlen, const u_char *buf)
-{
- struct spi_flash *flash = mtd->priv;
- int err;
-
- err = spi_flash_write(flash, to, len, buf);
- if (!err)
- *retlen = len;
-
- return err;
-}
-
-static void spi_flash_mtd_sync(struct mtd_info *mtd)
-{
-}
-
-static int spi_flash_mtd_number(void)
-{
-#ifdef CONFIG_SYS_MAX_FLASH_BANKS
- return CONFIG_SYS_MAX_FLASH_BANKS;
-#else
- return 0;
-#endif
-}
-
-int spi_flash_mtd_register(struct spi_flash *flash)
-{
- memset(&sf_mtd_info, 0, sizeof(sf_mtd_info));
- sprintf(sf_mtd_name, "nor%d", spi_flash_mtd_number());
-
- sf_mtd_info.name = sf_mtd_name;
- sf_mtd_info.type = MTD_NORFLASH;
- sf_mtd_info.flags = MTD_CAP_NORFLASH;
- sf_mtd_info.writesize = 1;
- sf_mtd_info.writebufsize = flash->page_size;
-
- sf_mtd_info._erase = spi_flash_mtd_erase;
- sf_mtd_info._read = spi_flash_mtd_read;
- sf_mtd_info._write = spi_flash_mtd_write;
- sf_mtd_info._sync = spi_flash_mtd_sync;
-
- sf_mtd_info.size = flash->size;
- sf_mtd_info.priv = flash;
-
- /* Only uniform flash devices for now */
- sf_mtd_info.numeraseregions = 0;
- sf_mtd_info.erasesize = flash->sector_size;
-
- return add_mtd_device(&sf_mtd_info);
-}
-
-void spi_flash_mtd_unregister(void)
-{
- del_mtd_device(&sf_mtd_info);
-}
--
1.9.1
^ permalink raw reply related [flat|nested] 16+ messages in thread
* [U-Boot] [PATCH 8/8] configs: Remove CONFIG_SPI_FLASH_MTD
2015-10-12 19:54 [U-Boot] [PATCH 1/8] sf: Add MTD support to spi_flash Jagan Teki
` (5 preceding siblings ...)
2015-10-12 19:54 ` [U-Boot] [PATCH 7/8] sf: Drop SPI_FLASH_MTD driver Jagan Teki
@ 2015-10-12 19:54 ` Jagan Teki
2015-10-29 6:04 ` [U-Boot] [PATCH 1/8] sf: Add MTD support to spi_flash Heiko Schocher
7 siblings, 0 replies; 16+ messages in thread
From: Jagan Teki @ 2015-10-12 19:54 UTC (permalink / raw)
To: u-boot
No explict spi-flash mtd handling driver, it's been
part of spi-flash layer iteself, hence removed it from
board configs.
Signed-off-by: Jagan Teki <jteki@openedev.com>
Cc: Daniel Schwierzeck <daniel.schwierzeck@gmail.com>
Cc: Heiko Schocher <hs@denx.de>
---
include/configs/aristainetos-common.h | 1 -
include/configs/gw_ventana.h | 1 -
include/configs/socfpga_common.h | 1 -
3 files changed, 3 deletions(-)
diff --git a/include/configs/aristainetos-common.h b/include/configs/aristainetos-common.h
index f03297e..a7d938b 100644
--- a/include/configs/aristainetos-common.h
+++ b/include/configs/aristainetos-common.h
@@ -42,7 +42,6 @@
#define CONFIG_PHY_MICREL
#define CONFIG_CMD_SF
-#define CONFIG_SPI_FLASH_MTD
#define CONFIG_SPI_FLASH_STMICRO
#define CONFIG_MXC_SPI
#define CONFIG_SF_DEFAULT_SPEED 20000000
diff --git a/include/configs/gw_ventana.h b/include/configs/gw_ventana.h
index 484d763..a63db66 100644
--- a/include/configs/gw_ventana.h
+++ b/include/configs/gw_ventana.h
@@ -69,7 +69,6 @@
#define CONFIG_CMD_SF
#ifdef CONFIG_CMD_SF
#define CONFIG_MXC_SPI
- #define CONFIG_SPI_FLASH_MTD
#define CONFIG_SPI_FLASH_BAR
#define CONFIG_SPI_FLASH_WINBOND
#define CONFIG_SF_DEFAULT_BUS 0
diff --git a/include/configs/socfpga_common.h b/include/configs/socfpga_common.h
index cece095..f288350 100644
--- a/include/configs/socfpga_common.h
+++ b/include/configs/socfpga_common.h
@@ -196,7 +196,6 @@ unsigned int cm_get_l4_sp_clk_hz(void);
#define CONFIG_SPI_FLASH_STMICRO /* Micron/Numonyx flash */
#define CONFIG_SPI_FLASH_SPANSION /* Spansion flash */
#ifndef CONFIG_SPL_BUILD
-#define CONFIG_SPI_FLASH_MTD
#define CONFIG_CMD_MTDPARTS
#define CONFIG_MTD_DEVICE
#define CONFIG_MTD_PARTITIONS
--
1.9.1
^ permalink raw reply related [flat|nested] 16+ messages in thread
* [U-Boot] [PATCH 1/8] sf: Add MTD support to spi_flash
2015-10-12 19:54 [U-Boot] [PATCH 1/8] sf: Add MTD support to spi_flash Jagan Teki
` (6 preceding siblings ...)
2015-10-12 19:54 ` [U-Boot] [PATCH 8/8] configs: Remove CONFIG_SPI_FLASH_MTD Jagan Teki
@ 2015-10-29 6:04 ` Heiko Schocher
7 siblings, 0 replies; 16+ messages in thread
From: Heiko Schocher @ 2015-10-29 6:04 UTC (permalink / raw)
To: u-boot
Hello Jgan,
Am 12.10.2015 um 21:54 schrieb Jagan Teki:
> This patch adds mtd_info support to spi_flash layer, MTD has
> proven core for flash operations so adding MTD to spi_flash
> will extends more functionality.
>
> Signed-off-by: Jagan Teki <jteki@openedev.com>
> ---
> drivers/mtd/spi/sf_ops.c | 45 +++++++++++++++++++++++++--------------------
> drivers/mtd/spi/sf_probe.c | 26 ++++++++++++++++++--------
> include/spi_flash.h | 9 +++++----
> 3 files changed, 48 insertions(+), 32 deletions(-)
Reviewed-by: Heiko Schocher <hs@denx.de>
bye,
Heiko
>
> diff --git a/drivers/mtd/spi/sf_ops.c b/drivers/mtd/spi/sf_ops.c
> index 703099f..f5ee376 100644
> --- a/drivers/mtd/spi/sf_ops.c
> +++ b/drivers/mtd/spi/sf_ops.c
> @@ -146,7 +146,7 @@ static int spi_flash_read_bar(struct spi_flash *flash, u8 idcode0)
> u8 curr_bank = 0;
> int ret;
>
> - if (flash->size <= SPI_FLASH_16MB_BOUN)
> + if (flash->mtd->size <= SPI_FLASH_16MB_BOUN)
> goto bank_end;
>
> switch (idcode0) {
> @@ -176,8 +176,8 @@ static void spi_flash_dual(struct spi_flash *flash, u32 *addr)
> {
> switch (flash->dual_flash) {
> case SF_DUAL_STACKED_FLASH:
> - if (*addr >= (flash->size >> 1)) {
> - *addr -= flash->size >> 1;
> + if (*addr >= (flash->mtd->size >> 1)) {
> + *addr -= flash->mtd->size >> 1;
> flash->spi->flags |= SPI_XFER_U_PAGE;
> } else {
> flash->spi->flags &= ~SPI_XFER_U_PAGE;
> @@ -303,7 +303,7 @@ static int spi_flash_cmd_erase_ops(struct spi_flash *flash, u32 offset,
> u8 cmd[SPI_FLASH_CMD_LEN];
> int ret = -1;
>
> - erase_size = flash->erase_size;
> + erase_size = mtd->erasesize;
> if (offset % erase_size || len % erase_size) {
> debug("SF: Erase offset/length not multiple of erase size\n");
> return -1;
> @@ -693,7 +693,7 @@ int spi_flash_decode_fdt(const void *blob, struct spi_flash *flash)
> return 0;
> }
>
> - if (flash->size != size) {
> + if (flash->mtd->size != size) {
> debug("%s: Memory map must cover entire device\n", __func__);
> return -1;
> }
> @@ -705,6 +705,7 @@ int spi_flash_decode_fdt(const void *blob, struct spi_flash *flash)
>
> int spi_flash_scan(struct spi_flash *flash)
> {
> + struct mtd_info *mtd = flash->mtd;
> const struct spi_flash_params *params;
> u16 jedec, ext_jedec;
> u8 idcode[5];
> @@ -754,24 +755,27 @@ int spi_flash_scan(struct spi_flash *flash)
>
> /* Assign spi data */
> flash->name = params->name;
> + mtd->type = MTD_NORFLASH;
> + mtd->writesize = 1;
> + mtd->flags = MTD_CAP_NORFLASH;
> flash->memory_map = flash->spi->memory_map;
> flash->dual_flash = flash->spi->option;
>
> /* Assign spi_flash ops */
> - flash->write = spi_flash_cmd_write_ops;
> + mtd->_write = spi_flash_cmd_write_ops;
> #if defined(CONFIG_SPI_FLASH_SST)
> if (params->flags & SST_WR)
> flash->flags |= SNOR_F_SST_WR;
>
> if (params->flags & SNOR_F_SST_WR) {
> if (flash->spi->op_mode_tx & SPI_OPM_TX_BP)
> - flash->write = sst_write_bp;
> + mtd->_write = sst_write_bp;
> else
> - flash->write = sst_write_wp;
> + mtd->_write = sst_write_wp;
> }
> #endif
> - flash->erase = spi_flash_cmd_erase_ops;
> - flash->read = spi_flash_cmd_read_ops;
> + mtd->_erase = spi_flash_cmd_erase_ops;
> + mtd->_read = spi_flash_cmd_read_ops;
>
> /* Compute the flash size */
> flash->shift = (flash->dual_flash & SF_DUAL_PARALLEL_FLASH) ? 1 : 0;
> @@ -790,27 +794,28 @@ int spi_flash_scan(struct spi_flash *flash)
> flash->page_size = 256;
> }
> flash->page_size <<= flash->shift;
> + mtd->writebufsize = flash->page_size;
> flash->sector_size = params->sector_size << flash->shift;
> - flash->size = flash->sector_size * params->nr_sectors << flash->shift;
> + mtd->size = flash->sector_size * params->nr_sectors << flash->shift;
> #ifdef CONFIG_SF_DUAL_FLASH
> if (flash->dual_flash & SF_DUAL_STACKED_FLASH)
> - flash->size <<= 1;
> + mtd->size <<= 1;
> #endif
>
> /* Compute erase sector and command */
> if (params->flags & SECT_4K) {
> flash->erase_cmd = CMD_ERASE_4K;
> - flash->erase_size = 4096 << flash->shift;
> + mtd->erasesize = 4096 << flash->shift;
> } else if (params->flags & SECT_32K) {
> flash->erase_cmd = CMD_ERASE_32K;
> - flash->erase_size = 32768 << flash->shift;
> + mtd->erasesize = 32768 << flash->shift;
> } else {
> flash->erase_cmd = CMD_ERASE_64K;
> - flash->erase_size = flash->sector_size;
> + mtd->erasesize = flash->sector_size;
> }
>
> /* Now erase size becomes valid sector size */
> - flash->sector_size = flash->erase_size;
> + flash->sector_size = mtd->erasesize;
>
> /* Look for the fastest read cmd */
> cmd = fls(params->e_rd_cmd & flash->spi->op_mode_rx);
> @@ -882,8 +887,8 @@ int spi_flash_scan(struct spi_flash *flash)
> #ifndef CONFIG_SPL_BUILD
> printf("SF: Detected %s with page size ", flash->name);
> print_size(flash->page_size, ", erase size ");
> - print_size(flash->erase_size, ", total ");
> - print_size(flash->size, "");
> + print_size(mtd->erasesize, ", total ");
> + print_size(mtd->size, "");
> if (flash->memory_map)
> printf(", mapped at %p", flash->memory_map);
> puts("\n");
> @@ -891,9 +896,9 @@ int spi_flash_scan(struct spi_flash *flash)
>
> #ifndef CONFIG_SPI_FLASH_BAR
> if (((flash->dual_flash == SF_SINGLE_FLASH) &&
> - (flash->size > SPI_FLASH_16MB_BOUN)) ||
> + (mtd->size > SPI_FLASH_16MB_BOUN)) ||
> ((flash->dual_flash > SF_SINGLE_FLASH) &&
> - (flash->size > SPI_FLASH_16MB_BOUN << 1))) {
> + (mtd->size > SPI_FLASH_16MB_BOUN << 1))) {
> puts("SF: Warning - Only lower 16MiB accessible,");
> puts(" Full access #define CONFIG_SPI_FLASH_BAR\n");
> }
> diff --git a/drivers/mtd/spi/sf_probe.c b/drivers/mtd/spi/sf_probe.c
> index 87ac33e..b8704e2 100644
> --- a/drivers/mtd/spi/sf_probe.c
> +++ b/drivers/mtd/spi/sf_probe.c
> @@ -14,9 +14,15 @@
> #include <malloc.h>
> #include <spi.h>
> #include <spi_flash.h>
> +#include <linux/mtd/mtd.h>
>
> #include "sf_internal.h"
>
> +struct spi_flash_priv {
> + struct spi_flash flash;
> + struct mtd_info mtd;
> +};
> +
> #ifndef CONFIG_DM_SPI_FLASH
> struct spi_flash *spi_flash_probe_tail(struct spi_slave *bus)
> {
> @@ -123,12 +129,19 @@ int spi_flash_std_erase(struct udevice *dev, u32 offset, size_t len)
>
> int spi_flash_std_probe(struct udevice *dev)
> {
> - struct spi_flash *flash = dev_get_uclass_priv(dev);
> + struct spi_flash_priv *priv = dev_get_uclass_priv(dev);
> struct spi_slave *slave = dev_get_parentdata(dev);
> + struct spi_flash *flash;
> int ret;
>
> - flash->dev = dev;
> + flash = &priv->flash;
> + flash->mtd = &priv->mtd;
> +
> flash->spi = slave;
> + flash->priv = priv;
> +
> + priv->mtd.priv = flash;
> + flash->dev = dev;
>
> /* Claim spi bus */
> ret = spi_claim_bus(slave);
> @@ -143,19 +156,16 @@ int spi_flash_std_probe(struct udevice *dev)
> goto err_scan;
> }
>
> -#ifdef CONFIG_SPI_FLASH_MTD
> - ret = spi_flash_mtd_register(flash);
> + ret = add_mtd_device(&priv->mtd);
> if (ret) {
> printf("SF: failed to register mtd device: %d\n", ret);
> goto err_mtd;
> }
> -#endif
> +
> return ret;
>
> -#ifdef CONFIG_SPI_FLASH_MTD
> err_mtd:
> spi_free_slave(slave);
> -#endif
> err_scan:
> spi_release_bus(slave);
> return ret;
> @@ -177,7 +187,7 @@ U_BOOT_DRIVER(spi_flash_std) = {
> .id = UCLASS_SPI_FLASH,
> .of_match = spi_flash_std_ids,
> .probe = spi_flash_std_probe,
> - .priv_auto_alloc_size = sizeof(struct spi_flash),
> + .priv_auto_alloc_size = sizeof(struct spi_flash_priv),
> .ops = &spi_flash_std_ops,
> };
>
> diff --git a/include/spi_flash.h b/include/spi_flash.h
> index 0732172..d0af8d3 100644
> --- a/include/spi_flash.h
> +++ b/include/spi_flash.h
> @@ -17,6 +17,7 @@
>
> #include <dm.h> /* Because we dereference struct udevice here */
> #include <linux/types.h>
> +#include <linux/mtd/mtd.h>
>
> #ifndef CONFIG_SF_DEFAULT_SPEED
> # define CONFIG_SF_DEFAULT_SPEED 1000000
> @@ -36,16 +37,15 @@ struct spi_slave;
> /**
> * struct spi_flash - SPI flash structure
> *
> + * @mtd: point to a mtd_info structure
> * @spi: SPI slave
> * @dev: SPI flash device
> * @name: Name of SPI flash
> * @dual_flash: Indicates dual flash memories - dual stacked, parallel
> * @shift: Flash shift useful in dual parallel
> * @flags: Indication of spi flash flags
> - * @size: Total flash size
> * @page_size: Write (page) size
> * @sector_size: Sector size
> - * @erase_size: Erase size
> * @bank_read_cmd: Bank read cmd
> * @bank_write_cmd: Bank write cmd
> * @bank_curr: Current flash bank
> @@ -54,6 +54,7 @@ struct spi_slave;
> * @write_cmd: Write cmd - page and quad program.
> * @dummy_byte: Dummy cycles for read operation.
> * @memory_map: Address of read-only SPI flash access
> + * @priv: the private data
> * @read: Flash read ops: Read len bytes at offset into buf
> * Supported cmds: Fast Array Read
> * @write: Flash write ops: Write len bytes from buf into offset
> @@ -63,6 +64,7 @@ struct spi_slave;
> * return 0 - Success, 1 - Failure
> */
> struct spi_flash {
> + struct mtd_info *mtd;
> struct spi_slave *spi;
> #ifdef CONFIG_DM_SPI_FLASH
> struct udevice *dev;
> @@ -72,10 +74,8 @@ struct spi_flash {
> u8 shift;
> u16 flags;
>
> - u32 size;
> u32 page_size;
> u32 sector_size;
> - u32 erase_size;
> #ifdef CONFIG_SPI_FLASH_BAR
> u8 bank_read_cmd;
> u8 bank_write_cmd;
> @@ -87,6 +87,7 @@ struct spi_flash {
> u8 dummy_byte;
>
> void *memory_map;
> + void *priv;
> int (*read)(struct spi_flash *flash, u32 offset, size_t len, void *buf);
> int (*write)(struct spi_flash *flash, u32 offset, size_t len,
> const void *buf);
>
--
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
^ permalink raw reply [flat|nested] 16+ messages in thread
* [U-Boot] [PATCH 2/8] sf: Use mtd_info ops instead of spi_flash ops
2015-10-12 19:54 ` [U-Boot] [PATCH 2/8] sf: Use mtd_info ops instead of spi_flash ops Jagan Teki
@ 2015-10-29 6:29 ` Heiko Schocher
0 siblings, 0 replies; 16+ messages in thread
From: Heiko Schocher @ 2015-10-29 6:29 UTC (permalink / raw)
To: u-boot
Hello Jagan,
Am 12.10.2015 um 21:54 schrieb Jagan Teki:
> Since MTD support is added in spi_flash layer, this patch uses
> mtd_info operations instead of legacy spi_flash operations.
>
> Signed-off-by: Jagan Teki <jteki@openedev.com>
> ---
> drivers/mtd/spi/sf_ops.c | 66 ++++++++++++++++++++++++++++--------------------
> include/spi_flash.h | 24 ++++++++----------
> 2 files changed, 49 insertions(+), 41 deletions(-)
Reviewed-by: Heiko Schocher <hs@denx.de>
bye,
Heiko
>
> diff --git a/drivers/mtd/spi/sf_ops.c b/drivers/mtd/spi/sf_ops.c
> index f5ee376..d10ca45 100644
> --- a/drivers/mtd/spi/sf_ops.c
> +++ b/drivers/mtd/spi/sf_ops.c
> @@ -296,18 +296,16 @@ int spi_flash_write_common(struct spi_flash *flash, const u8 *cmd,
> return ret;
> }
>
> -static int spi_flash_cmd_erase_ops(struct spi_flash *flash, u32 offset,
> - size_t len)
> +static int spi_flash_cmd_erase_ops(struct mtd_info *mtd,
> + struct erase_info *instr)
> {
> - u32 erase_size, erase_addr;
> + struct spi_flash *flash = mtd->priv;
> + u32 offset, len, erase_addr;
> u8 cmd[SPI_FLASH_CMD_LEN];
> int ret = -1;
>
> - erase_size = mtd->erasesize;
> - if (offset % erase_size || len % erase_size) {
> - debug("SF: Erase offset/length not multiple of erase size\n");
> - return -1;
> - }
> + offset = instr->addr;
> + len = instr->len;
>
> cmd[0] = flash->erase_cmd;
> while (len) {
> @@ -330,19 +328,24 @@ static int spi_flash_cmd_erase_ops(struct spi_flash *flash, u32 offset,
> ret = spi_flash_write_common(flash, cmd, sizeof(cmd), NULL, 0);
> if (ret < 0) {
> debug("SF: erase failed\n");
> - break;
> + goto erase_err;
> }
>
> - offset += erase_size;
> - len -= erase_size;
> + offset += mtd->erasesize;
> + len -= mtd->erasesize;
> }
>
> return ret;
> +
> +erase_err:
> + instr->state = MTD_ERASE_FAILED;
> + return ret;
> }
>
> -static int spi_flash_cmd_write_ops(struct spi_flash *flash, u32 offset,
> - size_t len, const void *buf)
> +static int spi_flash_cmd_write_ops(struct mtd_info *mtd, loff_t offset,
> + size_t len, size_t *retlen, const u_char *buf)
> {
> + struct spi_flash *flash = mtd->priv;
> unsigned long byte_addr, page_size;
> u32 write_addr;
> size_t chunk_len, actual;
> @@ -384,6 +387,7 @@ static int spi_flash_cmd_write_ops(struct spi_flash *flash, u32 offset,
> }
>
> offset += chunk_len;
> + *retlen += chunk_len;
> }
>
> return ret;
> @@ -417,11 +421,12 @@ void __weak spi_flash_copy_mmap(void *data, void *offset, size_t len)
> memcpy(data, offset, len);
> }
>
> -static int spi_flash_cmd_read_ops(struct spi_flash *flash, u32 offset,
> - size_t len, void *data)
> +static int spi_flash_cmd_read_ops(struct mtd_info *mtd, loff_t offset,
> + size_t len, size_t *retlen, u_char *data)
> {
> - u8 *cmd, cmdsz;
> + struct spi_flash *flash = mtd->priv;
> u32 remain_len, read_len, read_addr;
> + u8 *cmd, cmdsz;
> int bank_sel = 0;
> int ret = -1;
>
> @@ -478,6 +483,7 @@ static int spi_flash_cmd_read_ops(struct spi_flash *flash, u32 offset,
> offset += read_len;
> len -= read_len;
> data += read_len;
> + *retlen += read_len;
> }
>
> free(cmd);
> @@ -485,7 +491,8 @@ static int spi_flash_cmd_read_ops(struct spi_flash *flash, u32 offset,
> }
>
> #ifdef CONFIG_SPI_FLASH_SST
> -static int sst_byte_write(struct spi_flash *flash, u32 offset, const void *buf)
> +static int sst_byte_write(struct spi_flash *flash, u32 offset,
> + const void *buf, size_t *retlen)
> {
> int ret;
> u8 cmd[4] = {
> @@ -506,12 +513,15 @@ static int sst_byte_write(struct spi_flash *flash, u32 offset, const void *buf)
> if (ret)
> return ret;
>
> + *retlen += 1;
> +
> return spi_flash_cmd_wait_ready(flash, SPI_FLASH_PROG_TIMEOUT);
> }
>
> -static int sst_write_wp(struct spi_flash *flash, u32 offset, size_t len,
> - const void *buf)
> +static int sst_write_wp(struct mtd_info *mtd, loff_t offset, size_t len,
> + size_t *retlen, const u_char *buf)
> {
> + struct spi_flash *flash = mtd->priv;
> size_t actual, cmd_len;
> int ret;
> u8 cmd[4];
> @@ -525,7 +535,7 @@ static int sst_write_wp(struct spi_flash *flash, u32 offset, size_t len,
> /* If the data is not word aligned, write out leading single byte */
> actual = offset % 2;
> if (actual) {
> - ret = sst_byte_write(flash, offset, buf);
> + ret = sst_byte_write(flash, offset, buf, retlen);
> if (ret)
> goto done;
> }
> @@ -542,7 +552,7 @@ static int sst_write_wp(struct spi_flash *flash, u32 offset, size_t len,
> cmd[3] = offset;
>
> for (; actual < len - 1; actual += 2) {
> - debug("WP[%02x]: 0x%p => cmd = { 0x%02x 0x%06x }\n",
> + debug("WP[%02x]: 0x%p => cmd = { 0x%02x 0x%06llx }\n",
> spi_w8r8(flash->spi, CMD_READ_STATUS), buf + actual,
> cmd[0], offset);
>
> @@ -559,6 +569,7 @@ static int sst_write_wp(struct spi_flash *flash, u32 offset, size_t len,
>
> cmd_len = 1;
> offset += 2;
> + *retlen += 2;
> }
>
> if (!ret)
> @@ -566,19 +577,20 @@ static int sst_write_wp(struct spi_flash *flash, u32 offset, size_t len,
>
> /* If there is a single trailing byte, write it out */
> if (!ret && actual != len)
> - ret = sst_byte_write(flash, offset, buf + actual);
> + ret = sst_byte_write(flash, offset, buf + actual, retlen);
>
> done:
> - debug("SF: sst: program %s %zu bytes @ 0x%zx\n",
> + debug("SF: sst: program %s %zu bytes @ 0x%llx\n",
> ret ? "failure" : "success", len, offset - actual);
>
> spi_release_bus(flash->spi);
> return ret;
> }
>
> -static int sst_write_bp(struct spi_flash *flash, u32 offset, size_t len,
> - const void *buf)
> +static int sst_write_bp(struct mtd_info *mtd, loff_t offset, size_t len,
> + size_t *retlen, const u_char *buf)
> {
> + struct spi_flash *flash = mtd->priv;
> size_t actual;
> int ret;
>
> @@ -589,7 +601,7 @@ static int sst_write_bp(struct spi_flash *flash, u32 offset, size_t len,
> }
>
> for (actual = 0; actual < len; actual++) {
> - ret = sst_byte_write(flash, offset, buf + actual);
> + ret = sst_byte_write(flash, offset, buf + actual, retlen);
> if (ret) {
> debug("SF: sst byte program failed\n");
> break;
> @@ -600,7 +612,7 @@ static int sst_write_bp(struct spi_flash *flash, u32 offset, size_t len,
> if (!ret)
> ret = spi_flash_cmd_write_disable(flash);
>
> - debug("SF: sst: program %s %zu bytes @ 0x%zx\n",
> + debug("SF: sst: program %s %zu bytes @ 0x%llx\n",
> ret ? "failure" : "success", len, offset - actual);
>
> spi_release_bus(flash->spi);
> diff --git a/include/spi_flash.h b/include/spi_flash.h
> index d0af8d3..fe03b8d 100644
> --- a/include/spi_flash.h
> +++ b/include/spi_flash.h
> @@ -55,13 +55,6 @@ struct spi_slave;
> * @dummy_byte: Dummy cycles for read operation.
> * @memory_map: Address of read-only SPI flash access
> * @priv: the private data
> - * @read: Flash read ops: Read len bytes at offset into buf
> - * Supported cmds: Fast Array Read
> - * @write: Flash write ops: Write len bytes from buf into offset
> - * Supported cmds: Page Program
> - * @erase: Flash erase ops: Erase len bytes from offset
> - * Supported cmds: Sector erase 4K, 32K, 64K
> - * return 0 - Success, 1 - Failure
> */
> struct spi_flash {
> struct mtd_info *mtd;
> @@ -88,10 +81,6 @@ struct spi_flash {
>
> void *memory_map;
> void *priv;
> - int (*read)(struct spi_flash *flash, u32 offset, size_t len, void *buf);
> - int (*write)(struct spi_flash *flash, u32 offset, size_t len,
> - const void *buf);
> - int (*erase)(struct spi_flash *flash, u32 offset, size_t len);
> };
>
> struct dm_spi_flash_ops {
> @@ -156,19 +145,26 @@ int spi_flash_remove(struct udevice *flash);
> static inline int spi_flash_read(struct spi_flash *flash, u32 offset,
> size_t len, void *buf)
> {
> - return spi_flash_read_dm(flash->dev, offset, len, buf);
> + return mtd_read(flash->mtd, offset, len, &len, (u_char *)buf);
> }
>
> static inline int spi_flash_write(struct spi_flash *flash, u32 offset,
> size_t len, const void *buf)
> {
> - return spi_flash_write_dm(flash->dev, offset, len, buf);
> + return mtd_write(flash->mtd, offset, len, &len, (u_char *)buf);
> }
>
> static inline int spi_flash_erase(struct spi_flash *flash, u32 offset,
> size_t len)
> {
> - return spi_flash_erase_dm(flash->dev, offset, len);
> + struct erase_info instr;
> +
> + instr.mtd = flash->mtd;
> + instr.addr = offset;
> + instr.len = len;
> + instr.callback = 0;
> +
> + return mtd_erase(flash->mtd, &instr);
> }
>
> struct sandbox_state;
>
--
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
^ permalink raw reply [flat|nested] 16+ messages in thread
* [U-Boot] [PATCH 3/8] cmd_sf: Use mtd->size instead of flash->size
2015-10-12 19:54 ` [U-Boot] [PATCH 3/8] cmd_sf: Use mtd->size instead of flash->size Jagan Teki
@ 2015-10-29 6:32 ` Heiko Schocher
0 siblings, 0 replies; 16+ messages in thread
From: Heiko Schocher @ 2015-10-29 6:32 UTC (permalink / raw)
To: u-boot
Hello Jagan,
Am 12.10.2015 um 21:54 schrieb Jagan Teki:
> Since mtd got added, replace flash->size with mtd->size.
>
> Signed-off-by: Jagan Teki <jteki@openedev.com>
> ---
> common/cmd_sf.c | 16 ++++++++--------
> 1 file changed, 8 insertions(+), 8 deletions(-)
Reviewed-by: Heiko Schocher <hs@denx.de>
bye,
Heiko
>
> diff --git a/common/cmd_sf.c b/common/cmd_sf.c
> index ac7f5df..a501376 100644
> --- a/common/cmd_sf.c
> +++ b/common/cmd_sf.c
> @@ -275,13 +275,13 @@ static int do_spi_flash_read_write(int argc, char * const argv[])
> return -1;
>
> if (mtd_arg_off_size(argc - 2, &argv[2], &dev, &offset, &len,
> - &maxsize, MTD_DEV_TYPE_NOR, flash->size))
> + &maxsize, MTD_DEV_TYPE_NOR, flash->mtd->size))
> return -1;
>
> /* Consistency checking */
> - if (offset + len > flash->size) {
> - printf("ERROR: attempting %s past flash size (%#x)\n",
> - argv[0], flash->size);
> + if (offset + len > flash->mtd->size) {
> + printf("ERROR: attempting %s past flash size (0x%llx)\n",
> + argv[0], flash->mtd->size);
> return 1;
> }
>
> @@ -327,7 +327,7 @@ static int do_spi_flash_erase(int argc, char * const argv[])
> return -1;
>
> if (mtd_arg_off(argv[1], &dev, &offset, &len, &maxsize,
> - MTD_DEV_TYPE_NOR, flash->size))
> + MTD_DEV_TYPE_NOR, flash->mtd->size))
> return -1;
>
> ret = sf_parse_len_arg(argv[2], &size);
> @@ -335,9 +335,9 @@ static int do_spi_flash_erase(int argc, char * const argv[])
> return -1;
>
> /* Consistency checking */
> - if (offset + size > flash->size) {
> - printf("ERROR: attempting %s past flash size (%#x)\n",
> - argv[0], flash->size);
> + if (offset + size > flash->mtd->size) {
> + printf("ERROR: attempting %s past flash size (0x%llx)\n",
> + argv[0], flash->mtd->size);
> return 1;
> }
>
>
--
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
^ permalink raw reply [flat|nested] 16+ messages in thread
* [U-Boot] [PATCH 4/8] dm-sf: use mtd_ops, drop dm_spi_flash_ops
2015-10-12 19:54 ` [U-Boot] [PATCH 4/8] dm-sf: use mtd_ops, drop dm_spi_flash_ops Jagan Teki
@ 2015-10-29 6:35 ` Heiko Schocher
2015-10-29 13:11 ` Jagan Teki
0 siblings, 1 reply; 16+ messages in thread
From: Heiko Schocher @ 2015-10-29 6:35 UTC (permalink / raw)
To: u-boot
Hello Jagan,
Am 12.10.2015 um 21:54 schrieb Jagan Teki:
> Since mtd_info ops got introduced, just drop the unneeded
> dm_spi_flash operations.
>
> Signed-off-by: Jagan Teki <jteki@openedev.com>
> ---
> drivers/mtd/spi/sf-uclass.c | 16 --------
> drivers/mtd/spi/sf_probe.c | 30 ---------------
> include/spi_flash.h | 91 +++++++--------------------------------------
> 3 files changed, 14 insertions(+), 123 deletions(-)
Does this not break: drivers/mtd/spi/sf-uclass.c ?
added simon to cc.
bye,
Heiko
>
> diff --git a/drivers/mtd/spi/sf-uclass.c b/drivers/mtd/spi/sf-uclass.c
> index 350e21a..5cdbd1b 100644
> --- a/drivers/mtd/spi/sf-uclass.c
> +++ b/drivers/mtd/spi/sf-uclass.c
> @@ -11,22 +11,6 @@
> #include <dm/device-internal.h>
> #include "sf_internal.h"
>
> -int spi_flash_read_dm(struct udevice *dev, u32 offset, size_t len, void *buf)
> -{
> - return sf_get_ops(dev)->read(dev, offset, len, buf);
> -}
> -
> -int spi_flash_write_dm(struct udevice *dev, u32 offset, size_t len,
> - const void *buf)
> -{
> - return sf_get_ops(dev)->write(dev, offset, len, buf);
> -}
> -
> -int spi_flash_erase_dm(struct udevice *dev, u32 offset, size_t len)
> -{
> - return sf_get_ops(dev)->erase(dev, offset, len);
> -}
> -
> /*
> * TODO(sjg at chromium.org): This is an old-style function. We should remove
> * it when all SPI flash drivers use dm
> diff --git a/drivers/mtd/spi/sf_probe.c b/drivers/mtd/spi/sf_probe.c
> index b8704e2..5e314e2 100644
> --- a/drivers/mtd/spi/sf_probe.c
> +++ b/drivers/mtd/spi/sf_probe.c
> @@ -104,29 +104,6 @@ void spi_flash_free(struct spi_flash *flash)
>
> #else /* defined CONFIG_DM_SPI_FLASH */
>
> -static int spi_flash_std_read(struct udevice *dev, u32 offset, size_t len,
> - void *buf)
> -{
> - struct spi_flash *flash = dev_get_uclass_priv(dev);
> -
> - return flash->read(flash, offset, len, buf);
> -}
> -
> -int spi_flash_std_write(struct udevice *dev, u32 offset, size_t len,
> - const void *buf)
> -{
> - struct spi_flash *flash = dev_get_uclass_priv(dev);
> -
> - return flash->write(flash, offset, len, buf);
> -}
> -
> -int spi_flash_std_erase(struct udevice *dev, u32 offset, size_t len)
> -{
> - struct spi_flash *flash = dev_get_uclass_priv(dev);
> -
> - return flash->erase(flash, offset, len);
> -}
> -
> int spi_flash_std_probe(struct udevice *dev)
> {
> struct spi_flash_priv *priv = dev_get_uclass_priv(dev);
> @@ -171,12 +148,6 @@ err_scan:
> return ret;
> }
>
> -static const struct dm_spi_flash_ops spi_flash_std_ops = {
> - .read = spi_flash_std_read,
> - .write = spi_flash_std_write,
> - .erase = spi_flash_std_erase,
> -};
> -
> static const struct udevice_id spi_flash_std_ids[] = {
> { .compatible = "spi-flash" },
> { }
> @@ -188,7 +159,6 @@ U_BOOT_DRIVER(spi_flash_std) = {
> .of_match = spi_flash_std_ids,
> .probe = spi_flash_std_probe,
> .priv_auto_alloc_size = sizeof(struct spi_flash_priv),
> - .ops = &spi_flash_std_ops,
> };
>
> #endif /* CONFIG_DM_SPI_FLASH */
> diff --git a/include/spi_flash.h b/include/spi_flash.h
> index fe03b8d..8dd000d 100644
> --- a/include/spi_flash.h
> +++ b/include/spi_flash.h
> @@ -83,52 +83,7 @@ struct spi_flash {
> void *priv;
> };
>
> -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,
> - const void *buf);
> - int (*erase)(struct udevice *dev, u32 offset, size_t len);
> -};
> -
> -/* Access the serial operations for a device */
> -#define sf_get_ops(dev) ((struct dm_spi_flash_ops *)(dev)->driver->ops)
> -
> #ifdef CONFIG_DM_SPI_FLASH
> -/**
> - * spi_flash_read_dm() - Read data from SPI flash
> - *
> - * @dev: SPI flash device
> - * @offset: Offset into device in bytes to read from
> - * @len: Number of bytes to read
> - * @buf: Buffer to put the data that is read
> - * @return 0 if OK, -ve on error
> - */
> -int spi_flash_read_dm(struct udevice *dev, u32 offset, size_t len, void *buf);
> -
> -/**
> - * spi_flash_write_dm() - Write data to SPI flash
> - *
> - * @dev: SPI flash device
> - * @offset: Offset into device in bytes to write to
> - * @len: Number of bytes to write
> - * @buf: Buffer containing bytes to write
> - * @return 0 if OK, -ve on error
> - */
> -int spi_flash_write_dm(struct udevice *dev, u32 offset, size_t len,
> - const void *buf);
> -
> -/**
> - * spi_flash_erase_dm() - Erase blocks of the SPI flash
> - *
> - * Note that @len must be a muiltiple of the flash sector size.
> - *
> - * @dev: SPI flash device
> - * @offset: Offset into device in bytes to start erasing
> - * @len: Number of bytes to erase
> - * @return 0 if OK, -ve on error
> - */
> -int spi_flash_erase_dm(struct udevice *dev, u32 offset, size_t len);
> -
> int spi_flash_probe_bus_cs(unsigned int busnum, unsigned int cs,
> unsigned int max_hz, unsigned int spi_mode,
> struct udevice **devp);
> @@ -142,31 +97,6 @@ void spi_flash_free(struct spi_flash *flash);
>
> int spi_flash_remove(struct udevice *flash);
>
> -static inline int spi_flash_read(struct spi_flash *flash, u32 offset,
> - size_t len, void *buf)
> -{
> - return mtd_read(flash->mtd, offset, len, &len, (u_char *)buf);
> -}
> -
> -static inline int spi_flash_write(struct spi_flash *flash, u32 offset,
> - size_t len, const void *buf)
> -{
> - return mtd_write(flash->mtd, offset, len, &len, (u_char *)buf);
> -}
> -
> -static inline int spi_flash_erase(struct spi_flash *flash, u32 offset,
> - size_t len)
> -{
> - struct erase_info instr;
> -
> - instr.mtd = flash->mtd;
> - instr.addr = offset;
> - instr.len = len;
> - instr.callback = 0;
> -
> - return mtd_erase(flash->mtd, &instr);
> -}
> -
> struct sandbox_state;
>
> int sandbox_sf_bind_emul(struct sandbox_state *state, int busnum, int cs,
> @@ -191,25 +121,32 @@ struct spi_flash *spi_flash_probe_fdt(const void *blob, int slave_node,
> int spi_node);
>
> void spi_flash_free(struct spi_flash *flash);
> +#endif
>
> static inline int spi_flash_read(struct spi_flash *flash, u32 offset,
> - size_t len, void *buf)
> + size_t len, void *buf)
> {
> - return flash->read(flash, offset, len, buf);
> + return mtd_read(flash->mtd, offset, len, &len, (u_char *)buf);
> }
>
> static inline int spi_flash_write(struct spi_flash *flash, u32 offset,
> - size_t len, const void *buf)
> + size_t len, const void *buf)
> {
> - return flash->write(flash, offset, len, buf);
> + return mtd_write(flash->mtd, offset, len, &len, (u_char *)buf);
> }
>
> static inline int spi_flash_erase(struct spi_flash *flash, u32 offset,
> - size_t len)
> + size_t len)
> {
> - return flash->erase(flash, offset, len);
> + struct erase_info instr;
> +
> + instr.mtd = flash->mtd;
> + instr.addr = offset;
> + instr.len = len;
> + instr.callback = 0;
> +
> + return mtd_erase(flash->mtd, &instr);
> }
> -#endif
>
> void spi_boot(void) __noreturn;
> void spi_spl_load_image(uint32_t offs, unsigned int size, void *vdst);
>
--
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
^ permalink raw reply [flat|nested] 16+ messages in thread
* [U-Boot] [PATCH 5/8] sf: Add MTD support for non-dm spi_flash interface
2015-10-12 19:54 ` [U-Boot] [PATCH 5/8] sf: Add MTD support for non-dm spi_flash interface Jagan Teki
@ 2015-10-29 6:37 ` Heiko Schocher
0 siblings, 0 replies; 16+ messages in thread
From: Heiko Schocher @ 2015-10-29 6:37 UTC (permalink / raw)
To: u-boot
Hello Jagan,
Am 12.10.2015 um 21:54 schrieb Jagan Teki:
> This patch adds MTD support to non-dm spi_flash
> interface code.
>
> Signed-off-by: Jagan Teki <jteki@openedev.com>
> ---
> drivers/mtd/spi/sf_probe.c | 26 ++++++++++++++------------
> 1 file changed, 14 insertions(+), 12 deletions(-)
Reviewed-by: Heiko Schocher <hs@denx.de>
bye,
Heiko
>
> diff --git a/drivers/mtd/spi/sf_probe.c b/drivers/mtd/spi/sf_probe.c
> index 5e314e2..60abaf2 100644
> --- a/drivers/mtd/spi/sf_probe.c
> +++ b/drivers/mtd/spi/sf_probe.c
> @@ -26,17 +26,24 @@ struct spi_flash_priv {
> #ifndef CONFIG_DM_SPI_FLASH
> struct spi_flash *spi_flash_probe_tail(struct spi_slave *bus)
> {
> + struct spi_flash_priv *priv;
> struct spi_flash *flash;
> int ret;
>
> - /* Allocate space if needed (not used by sf-uclass */
> - flash = calloc(1, sizeof(*flash));
> - if (!flash) {
> - debug("SF: Failed to allocate spi_flash\n");
> + /* Allocate space if needed (not used by sf-uclass) */
> + priv = calloc(1, sizeof(*priv));
> + if (!priv) {
> + debug("SF: Failed to allocate spi_flash_priv\n");
> return NULL;
> }
>
> + flash = &priv->flash;
> + flash->mtd = &priv->mtd;
> +
> flash->spi = bus;
> + flash->priv = priv;
> +
> + priv->mtd.priv = flash;
>
> /* Claim spi bus */
> ret = spi_claim_bus(bus);
> @@ -49,19 +56,16 @@ struct spi_flash *spi_flash_probe_tail(struct spi_slave *bus)
> if (ret)
> goto err_scan;
>
> -#ifdef CONFIG_SPI_FLASH_MTD
> - ret = spi_flash_mtd_register(flash);
> + ret = add_mtd_device(&priv->mtd);
> if (ret) {
> printf("SF: failed to register mtd device: %d\n", ret);
> goto err_mtd;
> }
> -#endif
> +
> return flash;
>
> -#ifdef CONFIG_SPI_FLASH_MTD
> err_mtd:
> spi_free_slave(bus);
> -#endif
> err_scan:
> spi_release_bus(bus);
> err_claim:
> @@ -95,9 +99,7 @@ struct spi_flash *spi_flash_probe_fdt(const void *blob, int slave_node,
>
> void spi_flash_free(struct spi_flash *flash)
> {
> -#ifdef CONFIG_SPI_FLASH_MTD
> - spi_flash_mtd_unregister();
> -#endif
> + del_mtd_device(flash->mtd);
> spi_free_slave(flash->spi);
> free(flash);
> }
>
--
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
^ permalink raw reply [flat|nested] 16+ messages in thread
* [U-Boot] [PATCH 6/8] sf: probe: Minor cleanup
2015-10-12 19:54 ` [U-Boot] [PATCH 6/8] sf: probe: Minor cleanup Jagan Teki
@ 2015-10-29 6:54 ` Heiko Schocher
0 siblings, 0 replies; 16+ messages in thread
From: Heiko Schocher @ 2015-10-29 6:54 UTC (permalink / raw)
To: u-boot
Hello Jagan,
Am 12.10.2015 um 21:54 schrieb Jagan Teki:
> - Use static for file-scope function
> - Remove unneeded header file
> - Use spi instead of slave notation for spi_slave {}
>
> Signed-off-by: Jagan Teki <jteki@openedev.com>
> ---
> drivers/mtd/spi/sf_probe.c | 14 +++++++-------
> 1 file changed, 7 insertions(+), 7 deletions(-)
Reviewed-by: Heiko Schocher <hs@denx.de>
bye,
Heiko
>
> diff --git a/drivers/mtd/spi/sf_probe.c b/drivers/mtd/spi/sf_probe.c
> index 60abaf2..112ab27 100644
> --- a/drivers/mtd/spi/sf_probe.c
> +++ b/drivers/mtd/spi/sf_probe.c
> @@ -24,7 +24,7 @@ struct spi_flash_priv {
> };
>
> #ifndef CONFIG_DM_SPI_FLASH
> -struct spi_flash *spi_flash_probe_tail(struct spi_slave *bus)
> +static struct spi_flash *spi_flash_probe_tail(struct spi_slave *bus)
> {
> struct spi_flash_priv *priv;
> struct spi_flash *flash;
> @@ -106,24 +106,24 @@ void spi_flash_free(struct spi_flash *flash)
>
> #else /* defined CONFIG_DM_SPI_FLASH */
>
> -int spi_flash_std_probe(struct udevice *dev)
> +static int spi_flash_std_probe(struct udevice *dev)
> {
> struct spi_flash_priv *priv = dev_get_uclass_priv(dev);
> - struct spi_slave *slave = dev_get_parentdata(dev);
> + struct spi_slave *spi = dev_get_parentdata(dev);
> struct spi_flash *flash;
> int ret;
>
> flash = &priv->flash;
> flash->mtd = &priv->mtd;
>
> - flash->spi = slave;
> + flash->spi = spi;
> flash->priv = priv;
>
> priv->mtd.priv = flash;
> flash->dev = dev;
>
> /* Claim spi bus */
> - ret = spi_claim_bus(slave);
> + ret = spi_claim_bus(spi);
> if (ret) {
> debug("SF: Failed to claim SPI bus: %d\n", ret);
> return ret;
> @@ -144,9 +144,9 @@ int spi_flash_std_probe(struct udevice *dev)
> return ret;
>
> err_mtd:
> - spi_free_slave(slave);
> + spi_free_slave(spi);
> err_scan:
> - spi_release_bus(slave);
> + spi_release_bus(spi);
> return ret;
> }
>
>
--
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
^ permalink raw reply [flat|nested] 16+ messages in thread
* [U-Boot] [PATCH 4/8] dm-sf: use mtd_ops, drop dm_spi_flash_ops
2015-10-29 6:35 ` Heiko Schocher
@ 2015-10-29 13:11 ` Jagan Teki
2015-11-06 3:15 ` Simon Glass
0 siblings, 1 reply; 16+ messages in thread
From: Jagan Teki @ 2015-10-29 13:11 UTC (permalink / raw)
To: u-boot
Hi Heiko,
On 29 October 2015 at 12:05, Heiko Schocher <hs@denx.de> wrote:
> Hello Jagan,
>
> Am 12.10.2015 um 21:54 schrieb Jagan Teki:
>>
>> Since mtd_info ops got introduced, just drop the unneeded
>> dm_spi_flash operations.
>>
>> Signed-off-by: Jagan Teki <jteki@openedev.com>
>> ---
>> drivers/mtd/spi/sf-uclass.c | 16 --------
>> drivers/mtd/spi/sf_probe.c | 30 ---------------
>> include/spi_flash.h | 91
>> +++++++--------------------------------------
>> 3 files changed, 14 insertions(+), 123 deletions(-)
>
>
> Does this not break: drivers/mtd/spi/sf-uclass.c ?
This wouldn't break the dm because mtd_info ops are common to dm or
non-dm spi-flash which I tuned in this series[1] That means the tuned
sf series is prior to this MTD.
>
> added simon to cc.
>
>
>>
>> diff --git a/drivers/mtd/spi/sf-uclass.c b/drivers/mtd/spi/sf-uclass.c
>> index 350e21a..5cdbd1b 100644
>> --- a/drivers/mtd/spi/sf-uclass.c
>> +++ b/drivers/mtd/spi/sf-uclass.c
>> @@ -11,22 +11,6 @@
>> #include <dm/device-internal.h>
>> #include "sf_internal.h"
>>
>> -int spi_flash_read_dm(struct udevice *dev, u32 offset, size_t len, void
>> *buf)
>> -{
>> - return sf_get_ops(dev)->read(dev, offset, len, buf);
>> -}
>> -
>> -int spi_flash_write_dm(struct udevice *dev, u32 offset, size_t len,
>> - const void *buf)
>> -{
>> - return sf_get_ops(dev)->write(dev, offset, len, buf);
>> -}
>> -
>> -int spi_flash_erase_dm(struct udevice *dev, u32 offset, size_t len)
>> -{
>> - return sf_get_ops(dev)->erase(dev, offset, len);
>> -}
>> -
>> /*
>> * TODO(sjg at chromium.org): This is an old-style function. We should
>> remove
>> * it when all SPI flash drivers use dm
>> diff --git a/drivers/mtd/spi/sf_probe.c b/drivers/mtd/spi/sf_probe.c
>> index b8704e2..5e314e2 100644
>> --- a/drivers/mtd/spi/sf_probe.c
>> +++ b/drivers/mtd/spi/sf_probe.c
>> @@ -104,29 +104,6 @@ void spi_flash_free(struct spi_flash *flash)
>>
>> #else /* defined CONFIG_DM_SPI_FLASH */
>>
>> -static int spi_flash_std_read(struct udevice *dev, u32 offset, size_t
>> len,
>> - void *buf)
>> -{
>> - struct spi_flash *flash = dev_get_uclass_priv(dev);
>> -
>> - return flash->read(flash, offset, len, buf);
>> -}
>> -
>> -int spi_flash_std_write(struct udevice *dev, u32 offset, size_t len,
>> - const void *buf)
>> -{
>> - struct spi_flash *flash = dev_get_uclass_priv(dev);
>> -
>> - return flash->write(flash, offset, len, buf);
>> -}
>> -
>> -int spi_flash_std_erase(struct udevice *dev, u32 offset, size_t len)
>> -{
>> - struct spi_flash *flash = dev_get_uclass_priv(dev);
>> -
>> - return flash->erase(flash, offset, len);
>> -}
>> -
>> int spi_flash_std_probe(struct udevice *dev)
>> {
>> struct spi_flash_priv *priv = dev_get_uclass_priv(dev);
>> @@ -171,12 +148,6 @@ err_scan:
>> return ret;
>> }
>>
>> -static const struct dm_spi_flash_ops spi_flash_std_ops = {
>> - .read = spi_flash_std_read,
>> - .write = spi_flash_std_write,
>> - .erase = spi_flash_std_erase,
>> -};
>> -
>> static const struct udevice_id spi_flash_std_ids[] = {
>> { .compatible = "spi-flash" },
>> { }
>> @@ -188,7 +159,6 @@ U_BOOT_DRIVER(spi_flash_std) = {
>> .of_match = spi_flash_std_ids,
>> .probe = spi_flash_std_probe,
>> .priv_auto_alloc_size = sizeof(struct spi_flash_priv),
>> - .ops = &spi_flash_std_ops,
>> };
>>
>> #endif /* CONFIG_DM_SPI_FLASH */
>> diff --git a/include/spi_flash.h b/include/spi_flash.h
>> index fe03b8d..8dd000d 100644
>> --- a/include/spi_flash.h
>> +++ b/include/spi_flash.h
>> @@ -83,52 +83,7 @@ struct spi_flash {
>> void *priv;
>> };
>>
>> -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,
>> - const void *buf);
>> - int (*erase)(struct udevice *dev, u32 offset, size_t len);
>> -};
>> -
>> -/* Access the serial operations for a device */
>> -#define sf_get_ops(dev) ((struct dm_spi_flash_ops *)(dev)->driver->ops)
>> -
>> #ifdef CONFIG_DM_SPI_FLASH
>> -/**
>> - * spi_flash_read_dm() - Read data from SPI flash
>> - *
>> - * @dev: SPI flash device
>> - * @offset: Offset into device in bytes to read from
>> - * @len: Number of bytes to read
>> - * @buf: Buffer to put the data that is read
>> - * @return 0 if OK, -ve on error
>> - */
>> -int spi_flash_read_dm(struct udevice *dev, u32 offset, size_t len, void
>> *buf);
>> -
>> -/**
>> - * spi_flash_write_dm() - Write data to SPI flash
>> - *
>> - * @dev: SPI flash device
>> - * @offset: Offset into device in bytes to write to
>> - * @len: Number of bytes to write
>> - * @buf: Buffer containing bytes to write
>> - * @return 0 if OK, -ve on error
>> - */
>> -int spi_flash_write_dm(struct udevice *dev, u32 offset, size_t len,
>> - const void *buf);
>> -
>> -/**
>> - * spi_flash_erase_dm() - Erase blocks of the SPI flash
>> - *
>> - * Note that @len must be a muiltiple of the flash sector size.
>> - *
>> - * @dev: SPI flash device
>> - * @offset: Offset into device in bytes to start erasing
>> - * @len: Number of bytes to erase
>> - * @return 0 if OK, -ve on error
>> - */
>> -int spi_flash_erase_dm(struct udevice *dev, u32 offset, size_t len);
>> -
>> int spi_flash_probe_bus_cs(unsigned int busnum, unsigned int cs,
>> unsigned int max_hz, unsigned int spi_mode,
>> struct udevice **devp);
>> @@ -142,31 +97,6 @@ void spi_flash_free(struct spi_flash *flash);
>>
>> int spi_flash_remove(struct udevice *flash);
>>
>> -static inline int spi_flash_read(struct spi_flash *flash, u32 offset,
>> - size_t len, void *buf)
>> -{
>> - return mtd_read(flash->mtd, offset, len, &len, (u_char *)buf);
>> -}
>> -
>> -static inline int spi_flash_write(struct spi_flash *flash, u32 offset,
>> - size_t len, const void *buf)
>> -{
>> - return mtd_write(flash->mtd, offset, len, &len, (u_char *)buf);
>> -}
>> -
>> -static inline int spi_flash_erase(struct spi_flash *flash, u32 offset,
>> - size_t len)
>> -{
>> - struct erase_info instr;
>> -
>> - instr.mtd = flash->mtd;
>> - instr.addr = offset;
>> - instr.len = len;
>> - instr.callback = 0;
>> -
>> - return mtd_erase(flash->mtd, &instr);
>> -}
>> -
>> struct sandbox_state;
>>
>> int sandbox_sf_bind_emul(struct sandbox_state *state, int busnum, int
>> cs,
>> @@ -191,25 +121,32 @@ struct spi_flash *spi_flash_probe_fdt(const void
>> *blob, int slave_node,
>> int spi_node);
>>
>> void spi_flash_free(struct spi_flash *flash);
>> +#endif
>>
>> static inline int spi_flash_read(struct spi_flash *flash, u32 offset,
>> - size_t len, void *buf)
>> + size_t len, void *buf)
>> {
>> - return flash->read(flash, offset, len, buf);
>> + return mtd_read(flash->mtd, offset, len, &len, (u_char *)buf);
>> }
>>
>> static inline int spi_flash_write(struct spi_flash *flash, u32 offset,
>> - size_t len, const void *buf)
>> + size_t len, const void *buf)
>> {
>> - return flash->write(flash, offset, len, buf);
>> + return mtd_write(flash->mtd, offset, len, &len, (u_char *)buf);
>> }
>>
>> static inline int spi_flash_erase(struct spi_flash *flash, u32 offset,
>> - size_t len)
>> + size_t len)
>> {
>> - return flash->erase(flash, offset, len);
>> + struct erase_info instr;
>> +
>> + instr.mtd = flash->mtd;
>> + instr.addr = offset;
>> + instr.len = len;
>> + instr.callback = 0;
>> +
>> + return mtd_erase(flash->mtd, &instr);
>> }
>> -#endif
>>
>> void spi_boot(void) __noreturn;
>> void spi_spl_load_image(uint32_t offs, unsigned int size, void *vdst);
[1] https://www.mail-archive.com/u-boot at lists.denx.de/msg190086.html
--
Jagan | openedev.
^ permalink raw reply [flat|nested] 16+ messages in thread
* [U-Boot] [PATCH 4/8] dm-sf: use mtd_ops, drop dm_spi_flash_ops
2015-10-29 13:11 ` Jagan Teki
@ 2015-11-06 3:15 ` Simon Glass
0 siblings, 0 replies; 16+ messages in thread
From: Simon Glass @ 2015-11-06 3:15 UTC (permalink / raw)
To: u-boot
Hi Jagan,
On 29 October 2015 at 07:11, Jagan Teki <jteki@openedev.com> wrote:
> Hi Heiko,
>
> On 29 October 2015 at 12:05, Heiko Schocher <hs@denx.de> wrote:
>> Hello Jagan,
>>
>> Am 12.10.2015 um 21:54 schrieb Jagan Teki:
>>>
>>> Since mtd_info ops got introduced, just drop the unneeded
>>> dm_spi_flash operations.
>>>
>>> Signed-off-by: Jagan Teki <jteki@openedev.com>
>>> ---
>>> drivers/mtd/spi/sf-uclass.c | 16 --------
>>> drivers/mtd/spi/sf_probe.c | 30 ---------------
>>> include/spi_flash.h | 91
>>> +++++++--------------------------------------
>>> 3 files changed, 14 insertions(+), 123 deletions(-)
>>
>>
>> Does this not break: drivers/mtd/spi/sf-uclass.c ?
>
> This wouldn't break the dm because mtd_info ops are common to dm or
> non-dm spi-flash which I tuned in this series[1] That means the tuned
> sf series is prior to this MTD.
>
>>
>> added simon to cc.
>>
>>
>>>
>>> diff --git a/drivers/mtd/spi/sf-uclass.c b/drivers/mtd/spi/sf-uclass.c
>>> index 350e21a..5cdbd1b 100644
>>> --- a/drivers/mtd/spi/sf-uclass.c
>>> +++ b/drivers/mtd/spi/sf-uclass.c
>>> @@ -11,22 +11,6 @@
>>> #include <dm/device-internal.h>
>>> #include "sf_internal.h"
>>>
>>> -int spi_flash_read_dm(struct udevice *dev, u32 offset, size_t len, void
>>> *buf)
>>> -{
>>> - return sf_get_ops(dev)->read(dev, offset, len, buf);
>>> -}
>>> -
>>> -int spi_flash_write_dm(struct udevice *dev, u32 offset, size_t len,
>>> - const void *buf)
>>> -{
>>> - return sf_get_ops(dev)->write(dev, offset, len, buf);
>>> -}
>>> -
>>> -int spi_flash_erase_dm(struct udevice *dev, u32 offset, size_t len)
>>> -{
>>> - return sf_get_ops(dev)->erase(dev, offset, len);
>>> -}
>>> -
These are the functions that we should keep. It is the the ones that
don't take a struct udevice parameter which should be removed...
Regards,
Simon
^ permalink raw reply [flat|nested] 16+ messages in thread
end of thread, other threads:[~2015-11-06 3:15 UTC | newest]
Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-10-12 19:54 [U-Boot] [PATCH 1/8] sf: Add MTD support to spi_flash Jagan Teki
2015-10-12 19:54 ` [U-Boot] [PATCH 2/8] sf: Use mtd_info ops instead of spi_flash ops Jagan Teki
2015-10-29 6:29 ` Heiko Schocher
2015-10-12 19:54 ` [U-Boot] [PATCH 3/8] cmd_sf: Use mtd->size instead of flash->size Jagan Teki
2015-10-29 6:32 ` Heiko Schocher
2015-10-12 19:54 ` [U-Boot] [PATCH 4/8] dm-sf: use mtd_ops, drop dm_spi_flash_ops Jagan Teki
2015-10-29 6:35 ` Heiko Schocher
2015-10-29 13:11 ` Jagan Teki
2015-11-06 3:15 ` Simon Glass
2015-10-12 19:54 ` [U-Boot] [PATCH 5/8] sf: Add MTD support for non-dm spi_flash interface Jagan Teki
2015-10-29 6:37 ` Heiko Schocher
2015-10-12 19:54 ` [U-Boot] [PATCH 6/8] sf: probe: Minor cleanup Jagan Teki
2015-10-29 6:54 ` Heiko Schocher
2015-10-12 19:54 ` [U-Boot] [PATCH 7/8] sf: Drop SPI_FLASH_MTD driver Jagan Teki
2015-10-12 19:54 ` [U-Boot] [PATCH 8/8] configs: Remove CONFIG_SPI_FLASH_MTD Jagan Teki
2015-10-29 6:04 ` [U-Boot] [PATCH 1/8] sf: Add MTD support to spi_flash Heiko Schocher
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.