Skip to content

Commit 1ea4eb0

Browse files
ikegami-tr-vignesh
authored andcommitted
mtd: cfi_cmdset_0002: Use chip_ready() for write on S29GL064N
The regression issue has been caused on S29GL064N and reported it. Also the change mentioned is to use chip_good() for buffered write. So disable the change on S29GL064N and use chip_ready() as before. Cc: Miquel Raynal <[email protected]> Cc: Richard Weinberger <[email protected]> Cc: Vignesh Raghavendra <[email protected]> Cc: [email protected] Cc: [email protected] Fixes: dfeae10("mtd: cfi_cmdset_0002: Change write buffer to check correct value") Signed-off-by: Tokunori Ikegami <[email protected]> Signed-off-by: Vignesh Raghavendra <[email protected]> Link: https://lore.kernel.org/r/[email protected]/ Link: https://lore.kernel.org/r/[email protected]
1 parent 7dbde53 commit 1ea4eb0

File tree

1 file changed

+47
-42
lines changed

1 file changed

+47
-42
lines changed

drivers/mtd/chips/cfi_cmdset_0002.c

Lines changed: 47 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
#define SST49LF040B 0x0050
4949
#define SST49LF008A 0x005a
5050
#define AT49BV6416 0x00d6
51+
#define S29GL064N_MN12 0x0c01
5152

5253
/*
5354
* Status Register bit description. Used by flash devices that don't
@@ -462,7 +463,7 @@ static struct cfi_fixup cfi_fixup_table[] = {
462463
{ CFI_MFR_AMD, 0x0056, fixup_use_secsi },
463464
{ CFI_MFR_AMD, 0x005C, fixup_use_secsi },
464465
{ CFI_MFR_AMD, 0x005F, fixup_use_secsi },
465-
{ CFI_MFR_AMD, 0x0c01, fixup_s29gl064n_sectors },
466+
{ CFI_MFR_AMD, S29GL064N_MN12, fixup_s29gl064n_sectors },
466467
{ CFI_MFR_AMD, 0x1301, fixup_s29gl064n_sectors },
467468
{ CFI_MFR_AMD, 0x1a00, fixup_s29gl032n_sectors },
468469
{ CFI_MFR_AMD, 0x1a01, fixup_s29gl032n_sectors },
@@ -801,22 +802,12 @@ static struct mtd_info *cfi_amdstd_setup(struct mtd_info *mtd)
801802
return NULL;
802803
}
803804

804-
/*
805-
* Return true if the chip is ready.
806-
*
807-
* Ready is one of: read mode, query mode, erase-suspend-read mode (in any
808-
* non-suspended sector) and is indicated by no toggle bits toggling.
809-
*
810-
* Note that anything more complicated than checking if no bits are toggling
811-
* (including checking DQ5 for an error status) is tricky to get working
812-
* correctly and is therefore not done (particularly with interleaved chips
813-
* as each chip must be checked independently of the others).
814-
*/
815-
static int __xipram chip_ready(struct map_info *map, struct flchip *chip,
816-
unsigned long addr)
805+
static int __xipram chip_check(struct map_info *map, struct flchip *chip,
806+
unsigned long addr, map_word *expected)
817807
{
818808
struct cfi_private *cfi = map->fldrv_priv;
819-
map_word d, t;
809+
map_word oldd, curd;
810+
int ret;
820811

821812
if (cfi_use_status_reg(cfi)) {
822813
map_word ready = CMD(CFI_SR_DRB);
@@ -826,17 +817,35 @@ static int __xipram chip_ready(struct map_info *map, struct flchip *chip,
826817
*/
827818
cfi_send_gen_cmd(0x70, cfi->addr_unlock1, chip->start, map, cfi,
828819
cfi->device_type, NULL);
829-
d = map_read(map, addr);
820+
curd = map_read(map, addr);
830821

831-
return map_word_andequal(map, d, ready, ready);
822+
return map_word_andequal(map, curd, ready, ready);
832823
}
833824

834-
d = map_read(map, addr);
835-
t = map_read(map, addr);
825+
oldd = map_read(map, addr);
826+
curd = map_read(map, addr);
827+
828+
ret = map_word_equal(map, oldd, curd);
836829

837-
return map_word_equal(map, d, t);
830+
if (!ret || !expected)
831+
return ret;
832+
833+
return map_word_equal(map, curd, *expected);
838834
}
839835

836+
/*
837+
* Return true if the chip is ready.
838+
*
839+
* Ready is one of: read mode, query mode, erase-suspend-read mode (in any
840+
* non-suspended sector) and is indicated by no toggle bits toggling.
841+
*
842+
* Note that anything more complicated than checking if no bits are toggling
843+
* (including checking DQ5 for an error status) is tricky to get working
844+
* correctly and is therefore not done (particularly with interleaved chips
845+
* as each chip must be checked independently of the others).
846+
*/
847+
#define chip_ready(map, chip, addr) chip_check(map, chip, addr, NULL)
848+
840849
/*
841850
* Return true if the chip is ready and has the correct value.
842851
*
@@ -855,28 +864,24 @@ static int __xipram chip_ready(struct map_info *map, struct flchip *chip,
855864
static int __xipram chip_good(struct map_info *map, struct flchip *chip,
856865
unsigned long addr, map_word expected)
857866
{
858-
struct cfi_private *cfi = map->fldrv_priv;
859-
map_word oldd, curd;
860-
861-
if (cfi_use_status_reg(cfi)) {
862-
map_word ready = CMD(CFI_SR_DRB);
867+
return chip_check(map, chip, addr, &expected);
868+
}
863869

864-
/*
865-
* For chips that support status register, check device
866-
* ready bit
867-
*/
868-
cfi_send_gen_cmd(0x70, cfi->addr_unlock1, chip->start, map, cfi,
869-
cfi->device_type, NULL);
870-
curd = map_read(map, addr);
870+
static bool cfi_use_chip_ready_for_write(struct map_info *map)
871+
{
872+
struct cfi_private *cfi = map->fldrv_priv;
871873

872-
return map_word_andequal(map, curd, ready, ready);
873-
}
874+
return cfi->mfr == CFI_MFR_AMD && cfi->id == S29GL064N_MN12;
875+
}
874876

875-
oldd = map_read(map, addr);
876-
curd = map_read(map, addr);
877+
static int __xipram chip_good_for_write(struct map_info *map,
878+
struct flchip *chip, unsigned long addr,
879+
map_word expected)
880+
{
881+
if (cfi_use_chip_ready_for_write(map))
882+
return chip_ready(map, chip, addr);
877883

878-
return map_word_equal(map, oldd, curd) &&
879-
map_word_equal(map, curd, expected);
884+
return chip_good(map, chip, addr, expected);
880885
}
881886

882887
static int get_chip(struct map_info *map, struct flchip *chip, unsigned long adr, int mode)
@@ -1699,15 +1704,15 @@ static int __xipram do_write_oneword_once(struct map_info *map,
16991704
* "chip_good" to avoid the failure due to scheduling.
17001705
*/
17011706
if (time_after(jiffies, timeo) &&
1702-
!chip_good(map, chip, adr, datum)) {
1707+
!chip_good_for_write(map, chip, adr, datum)) {
17031708
xip_enable(map, chip, adr);
17041709
printk(KERN_WARNING "MTD %s(): software timeout\n", __func__);
17051710
xip_disable(map, chip, adr);
17061711
ret = -EIO;
17071712
break;
17081713
}
17091714

1710-
if (chip_good(map, chip, adr, datum)) {
1715+
if (chip_good_for_write(map, chip, adr, datum)) {
17111716
if (cfi_check_err_status(map, chip, adr))
17121717
ret = -EIO;
17131718
break;
@@ -1979,14 +1984,14 @@ static int __xipram do_write_buffer_wait(struct map_info *map,
19791984
* "chip_good" to avoid the failure due to scheduling.
19801985
*/
19811986
if (time_after(jiffies, timeo) &&
1982-
!chip_good(map, chip, adr, datum)) {
1987+
!chip_good_for_write(map, chip, adr, datum)) {
19831988
pr_err("MTD %s(): software timeout, address:0x%.8lx.\n",
19841989
__func__, adr);
19851990
ret = -EIO;
19861991
break;
19871992
}
19881993

1989-
if (chip_good(map, chip, adr, datum)) {
1994+
if (chip_good_for_write(map, chip, adr, datum)) {
19901995
if (cfi_check_err_status(map, chip, adr))
19911996
ret = -EIO;
19921997
break;

0 commit comments

Comments
 (0)