Re: [PATCH v2 2/6] mtd: cfi: add writebufsize initialization

Guillaume LECERF
2010-12-30T10:32:38Z

[-- Attachment #1: Type: text/plain, Size: 222 bytes --]

2010/12/21 Artem Bityutskiy <dedekind1@gmail.com>:
> Yes, fair question, Anatolij?

Hi all.

Anatolij, what about such patches ?
Note : this is totally untested ;)

--
Guillaume LECERF
GeeXboX developer - www.geexbox.org

[-- Attachment #2: 04-v2-2-6-mtd-cfi-add-writebufsiz.patch --]
[-- Type: application/octet-stream, Size: 2210 bytes --]

[v2,2/6] mtd: cfi: add writebufsize initialization

From: Anatolij Gustschin <agust@denx.de>

Initialize mtd->writebufsize to the value obtained
by CFI query command at probe time.

Signed-off-by: Anatolij Gustschin <agust@denx.de>
Signed-off-by: Guillaume LECERF <glecerf@gmail.com>
---
drivers/mtd/chips/cfi_cmdset_0001.c | 1 +
drivers/mtd/chips/cfi_cmdset_0002.c | 4 ++++
drivers/mtd/chips/cfi_cmdset_0020.c | 1 +
3 files changed, 6 insertions(+), 0 deletions(-)

diff --git a/drivers/mtd/chips/cfi_cmdset_0001.c b/drivers/mtd/chips/cfi_cmdset_0001.c
index 44cbfc0..178f87b 100644
--- a/drivers/mtd/chips/cfi_cmdset_0001.c
+++ b/drivers/mtd/chips/cfi_cmdset_0001.c
@@ -455,6 +455,7 @@ struct mtd_info *cfi_cmdset_0001(struct map_info *map, int primary)
mtd->flags = MTD_CAP_NORFLASH;
mtd->name = map->name;
mtd->writesize = 1;
+ mtd->writebufsize = cfi_interleave(cfi) << cfi->cfiq->MaxBufWriteSize;

mtd->reboot_notifier.notifier_call = cfi_intelext_reboot;

diff --git a/drivers/mtd/chips/cfi_cmdset_0002.c b/drivers/mtd/chips/cfi_cmdset_0002.c
index a43ab45..e94f483 100644
--- a/drivers/mtd/chips/cfi_cmdset_0002.c
+++ b/drivers/mtd/chips/cfi_cmdset_0002.c
@@ -440,6 +440,10 @@ struct mtd_info *cfi_cmdset_0002(struct map_info *map, int primary)
mtd->flags = MTD_CAP_NORFLASH;
mtd->name = map->name;
mtd->writesize = 1;
+ mtd->writebufsize = cfi_interleave(cfi) << cfi->cfiq->MaxBufWriteSize;
+
+ DEBUG(MTD_DEBUG_LEVEL3, "MTD %s(): write buffer size %d\n",
+ __func__, mtd->writebufsize);

mtd->reboot_notifier.notifier_call = cfi_amdstd_reboot;

diff --git a/drivers/mtd/chips/cfi_cmdset_0020.c b/drivers/mtd/chips/cfi_cmdset_0020.c
index 314af1f..ed56ad3 100644
--- a/drivers/mtd/chips/cfi_cmdset_0020.c
+++ b/drivers/mtd/chips/cfi_cmdset_0020.c
@@ -238,6 +238,7 @@ static struct mtd_info *cfi_staa_setup(struct map_info *map)
mtd->resume = cfi_staa_resume;
mtd->flags = MTD_CAP_NORFLASH & ~MTD_BIT_WRITEABLE;
mtd->writesize = 8; /* FIXME: Should be 0 for STMicro flashes w/out ECC */
+ mtd->writebufsize = cfi_interleave(cfi) << cfi->cfiq->MaxBufWriteSize;
map->fldrv = &cfi_staa_chipdrv;
__module_get(THIS_MODULE);
mtd->name = map->name;

[-- Attachment #3: 08-patch.patch --]
[-- Type: application/octet-stream, Size: 5236 bytes --]

From: Guillaume LECERF <glecerf@gmail.com>

---
drivers/mtd/chips/cfi_cmdset_0001.c | 8 +++-----
drivers/mtd/chips/cfi_cmdset_0002.c | 3 +--
drivers/mtd/chips/cfi_cmdset_0020.c | 11 +++++------
drivers/mtd/chips/cfi_probe.c | 3 ++-
4 files changed, 11 insertions(+), 14 deletions(-)

diff --git a/drivers/mtd/chips/cfi_cmdset_0001.c b/drivers/mtd/chips/cfi_cmdset_0001.c
index 178f87b..6dbc44a 100644
--- a/drivers/mtd/chips/cfi_cmdset_0001.c
+++ b/drivers/mtd/chips/cfi_cmdset_0001.c
@@ -1650,16 +1650,15 @@ static int __xipram do_write_buffer(struct map_info *map, struct flchip *chip,
struct cfi_private *cfi = map->fldrv_priv;
map_word status, write_cmd, datum;
unsigned long cmd_adr;
- int ret, wbufsize, word_gap, words;
+ int ret, word_gap, words;
const struct kvec *vec;
unsigned long vec_seek;
unsigned long initial_adr;
int initial_len = len;

- wbufsize = cfi_interleave(cfi) << cfi->cfiq->MaxBufWriteSize;
adr += chip->start;
initial_adr = adr;
- cmd_adr = adr & ~(wbufsize-1);
+ cmd_adr = adr & ~(mtd->writebufsize - 1);

/* Let's determine this according to the interleave only once */
write_cmd = (cfi->cfiq->P_ID != P_ID_INTEL_PERFORMANCE) ? CMD(0xe8) : CMD(0xe9);
@@ -1807,7 +1806,6 @@ static int cfi_intelext_writev (struct mtd_info *mtd, const struct kvec *vecs,
{
struct map_info *map = mtd->priv;
struct cfi_private *cfi = map->fldrv_priv;
- int wbufsize = cfi_interleave(cfi) << cfi->cfiq->MaxBufWriteSize;
int ret = 0;
int chipnum;
unsigned long ofs, vec_seek, i;
@@ -1826,7 +1824,7 @@ static int cfi_intelext_writev (struct mtd_info *mtd, const struct kvec *vecs,

do {
/* We must not cross write block boundaries */
- int size = wbufsize - (ofs & (wbufsize-1));
+ int size = mtd->writebufsize - (ofs & (mtd->writebufsize - 1));

if (size > len)
size = len;
diff --git a/drivers/mtd/chips/cfi_cmdset_0002.c b/drivers/mtd/chips/cfi_cmdset_0002.c
index e94f483..c4f8675 100644
--- a/drivers/mtd/chips/cfi_cmdset_0002.c
+++ b/drivers/mtd/chips/cfi_cmdset_0002.c
@@ -1492,7 +1492,6 @@ static int cfi_amdstd_write_buffers(struct mtd_info *mtd, loff_t to, size_t len,
{
struct map_info *map = mtd->priv;
struct cfi_private *cfi = map->fldrv_priv;
- int wbufsize = cfi_interleave(cfi) << cfi->cfiq->MaxBufWriteSize;
int ret = 0;
int chipnum;
unsigned long ofs;
@@ -1528,7 +1527,7 @@ static int cfi_amdstd_write_buffers(struct mtd_info *mtd, loff_t to, size_t len,
/* Write buffer is worth it only if more than one word to write... */
while (len >= map_bankwidth(map) * 2) {
/* We must not cross write block boundaries */
- int size = wbufsize - (ofs & (wbufsize-1));
+ int size = mtd->writebufsize - (ofs & (mtd->writebufsize - 1));

if (size > len)
size = len;
diff --git a/drivers/mtd/chips/cfi_cmdset_0020.c b/drivers/mtd/chips/cfi_cmdset_0020.c
index ed56ad3..bd8a550 100644
--- a/drivers/mtd/chips/cfi_cmdset_0020.c
+++ b/drivers/mtd/chips/cfi_cmdset_0020.c
@@ -426,15 +426,14 @@ static inline int do_write_buffer(struct map_info *map, struct flchip *chip,
map_word status, status_OK;
unsigned long cmd_adr, timeo;
DECLARE_WAITQUEUE(wait, current);
- int wbufsize, z;
+ int z;

/* M58LW064A requires bus alignment for buffer wriets -- saw */
if (adr & (map_bankwidth(map)-1))
return -EINVAL;

- wbufsize = cfi_interleave(cfi) << cfi->cfiq->MaxBufWriteSize;
adr += chip->start;
- cmd_adr = adr & ~(wbufsize-1);
+ cmd_adr = adr & ~(mtd->writebufsize - 1);

/* Let's determine this according to the interleave only once */
status_OK = CMD(0x80);
@@ -610,7 +609,6 @@ static int cfi_staa_write_buffers (struct mtd_info *mtd, loff_t to,
{
struct map_info *map = mtd->priv;
struct cfi_private *cfi = map->fldrv_priv;
- int wbufsize = cfi_interleave(cfi) << cfi->cfiq->MaxBufWriteSize;
int ret = 0;
int chipnum;
unsigned long ofs;
@@ -624,14 +622,15 @@ static int cfi_staa_write_buffers (struct mtd_info *mtd, loff_t to,

#ifdef DEBUG_CFI_FEATURES
printk("%s: map_bankwidth(map)[%x]\n", __func__, map_bankwidth(map));
- printk("%s: chipnum[%x] wbufsize[%x]\n", __func__, chipnum, wbufsize);
+ printk(KERN_DEBUG "%s: chipnum[%x] mtd->writebufsize[%x]\n", __func__,
+ chipnum, mtd->writebufsize);
printk("%s: ofs[%x] len[%x]\n", __func__, ofs, len);
#endif

/* Write buffer is worth it only if more than one word to write... */
while (len > 0) {
/* We must not cross write block boundaries */
- int size = wbufsize - (ofs & (wbufsize-1));
+ int size = mtd->writebufsize - (ofs & (mtd->writebufsize - 1));

if (size > len)
size = len;
diff --git a/drivers/mtd/chips/cfi_probe.c b/drivers/mtd/chips/cfi_probe.c
index d255352..8f3135f 100644
--- a/drivers/mtd/chips/cfi_probe.c
+++ b/drivers/mtd/chips/cfi_probe.c
@@ -377,7 +377,8 @@ static void print_cfi_ident(struct cfi_ident *cfip)
break;
}

- printk("Max. bytes in buffer write: 0x%x\n", 1<< cfip->MaxBufWriteSize);
+ printk(KERN_DEBUG "Max. bytes in buffer write: 0x%x\n",
+ cfi_interleave(cfi) << cfip->MaxBufWriteSize);
printk("Number of Erase Block Regions: %d\n", cfip->NumEraseRegions);

}