Skip to content

Commit be0b86c

Browse files
committed
mtd: spinand: Gather all the bus interface steps in one single function
Writing the quad enable bit in one helper and doing the chip configuration in another does not make much sense from a bus interface setup point of view. Instead, let's create a broader helper which is going to be in charge of all the bus configuration steps at once. This will specifically allow to transition to octal DDR mode, and even fallback to quad (if suppoorted) or single mode otherwise. Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
1 parent ef1ed29 commit be0b86c

1 file changed

Lines changed: 37 additions & 25 deletions

File tree

drivers/mtd/nand/spi/core.c

Lines changed: 37 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -261,18 +261,9 @@ static int spinand_init_cfg_cache(struct spinand_device *spinand)
261261
return 0;
262262
}
263263

264-
static int spinand_init_quad_enable(struct spinand_device *spinand)
264+
static int spinand_init_quad_enable(struct spinand_device *spinand,
265+
bool enable)
265266
{
266-
bool enable = false;
267-
268-
if (!(spinand->flags & SPINAND_HAS_QE_BIT))
269-
return 0;
270-
271-
if (spinand->op_templates->read_cache->data.buswidth == 4 ||
272-
spinand->op_templates->write_cache->data.buswidth == 4 ||
273-
spinand->op_templates->update_cache->data.buswidth == 4)
274-
enable = true;
275-
276267
return spinand_upd_cfg(spinand, CFG_QUAD_ENABLE,
277268
enable ? CFG_QUAD_ENABLE : 0);
278269
}
@@ -1392,12 +1383,6 @@ static int spinand_manufacturer_init(struct spinand_device *spinand)
13921383
return ret;
13931384
}
13941385

1395-
if (spinand->configure_chip) {
1396-
ret = spinand->configure_chip(spinand);
1397-
if (ret)
1398-
return ret;
1399-
}
1400-
14011386
return 0;
14021387
}
14031388

@@ -1600,6 +1585,31 @@ static int spinand_detect(struct spinand_device *spinand)
16001585
return 0;
16011586
}
16021587

1588+
static int spinand_configure_chip(struct spinand_device *spinand)
1589+
{
1590+
bool quad_enable = false;
1591+
int ret;
1592+
1593+
if (spinand->flags & SPINAND_HAS_QE_BIT) {
1594+
if (spinand->ssdr_op_templates.read_cache->data.buswidth == 4 ||
1595+
spinand->ssdr_op_templates.write_cache->data.buswidth == 4 ||
1596+
spinand->ssdr_op_templates.update_cache->data.buswidth == 4)
1597+
quad_enable = true;
1598+
}
1599+
1600+
ret = spinand_init_quad_enable(spinand, quad_enable);
1601+
if (ret)
1602+
return ret;
1603+
1604+
if (spinand->configure_chip) {
1605+
ret = spinand->configure_chip(spinand);
1606+
if (ret)
1607+
return ret;
1608+
}
1609+
1610+
return ret;
1611+
}
1612+
16031613
static int spinand_init_flash(struct spinand_device *spinand)
16041614
{
16051615
struct device *dev = &spinand->spimem->spi->dev;
@@ -1610,10 +1620,6 @@ static int spinand_init_flash(struct spinand_device *spinand)
16101620
if (ret)
16111621
return ret;
16121622

1613-
ret = spinand_init_quad_enable(spinand);
1614-
if (ret)
1615-
return ret;
1616-
16171623
ret = spinand_upd_cfg(spinand, CFG_OTP_ENABLE, 0);
16181624
if (ret)
16191625
return ret;
@@ -1626,19 +1632,25 @@ static int spinand_init_flash(struct spinand_device *spinand)
16261632
return ret;
16271633
}
16281634

1635+
ret = spinand_configure_chip(spinand);
1636+
if (ret)
1637+
goto manuf_cleanup;
1638+
16291639
/* After power up, all blocks are locked, so unlock them here. */
16301640
for (i = 0; i < nand->memorg.ntargets; i++) {
16311641
ret = spinand_select_target(spinand, i);
16321642
if (ret)
1633-
break;
1643+
goto manuf_cleanup;
16341644

16351645
ret = spinand_lock_block(spinand, BL_ALL_UNLOCKED);
16361646
if (ret)
1637-
break;
1647+
goto manuf_cleanup;
16381648
}
16391649

1640-
if (ret)
1641-
spinand_manufacturer_cleanup(spinand);
1650+
return 0;
1651+
1652+
manuf_cleanup:
1653+
spinand_manufacturer_cleanup(spinand);
16421654

16431655
return ret;
16441656
}

0 commit comments

Comments
 (0)