Skip to content

Commit d4e2237

Browse files
miquelraynalgregkh
authored andcommitted
mtd: spinand: Gather all the bus interface steps in one single function
[ Upstream commit be0b86c ] 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> Stable-dep-of: 25a915f ("mtd: spinand: winbond: Clarify when to enable the HS bit") Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent a602b7e commit d4e2237

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
@@ -177,18 +177,9 @@ static int spinand_init_cfg_cache(struct spinand_device *spinand)
177177
return 0;
178178
}
179179

180-
static int spinand_init_quad_enable(struct spinand_device *spinand)
180+
static int spinand_init_quad_enable(struct spinand_device *spinand,
181+
bool enable)
181182
{
182-
bool enable = false;
183-
184-
if (!(spinand->flags & SPINAND_HAS_QE_BIT))
185-
return 0;
186-
187-
if (spinand->op_templates->read_cache->data.buswidth == 4 ||
188-
spinand->op_templates->write_cache->data.buswidth == 4 ||
189-
spinand->op_templates->update_cache->data.buswidth == 4)
190-
enable = true;
191-
192183
return spinand_upd_cfg(spinand, CFG_QUAD_ENABLE,
193184
enable ? CFG_QUAD_ENABLE : 0);
194185
}
@@ -1314,12 +1305,6 @@ static int spinand_manufacturer_init(struct spinand_device *spinand)
13141305
return ret;
13151306
}
13161307

1317-
if (spinand->configure_chip) {
1318-
ret = spinand->configure_chip(spinand);
1319-
if (ret)
1320-
return ret;
1321-
}
1322-
13231308
return 0;
13241309
}
13251310

@@ -1496,6 +1481,31 @@ static int spinand_detect(struct spinand_device *spinand)
14961481
return 0;
14971482
}
14981483

1484+
static int spinand_configure_chip(struct spinand_device *spinand)
1485+
{
1486+
bool quad_enable = false;
1487+
int ret;
1488+
1489+
if (spinand->flags & SPINAND_HAS_QE_BIT) {
1490+
if (spinand->ssdr_op_templates.read_cache->data.buswidth == 4 ||
1491+
spinand->ssdr_op_templates.write_cache->data.buswidth == 4 ||
1492+
spinand->ssdr_op_templates.update_cache->data.buswidth == 4)
1493+
quad_enable = true;
1494+
}
1495+
1496+
ret = spinand_init_quad_enable(spinand, quad_enable);
1497+
if (ret)
1498+
return ret;
1499+
1500+
if (spinand->configure_chip) {
1501+
ret = spinand->configure_chip(spinand);
1502+
if (ret)
1503+
return ret;
1504+
}
1505+
1506+
return ret;
1507+
}
1508+
14991509
static int spinand_init_flash(struct spinand_device *spinand)
15001510
{
15011511
struct device *dev = &spinand->spimem->spi->dev;
@@ -1506,10 +1516,6 @@ static int spinand_init_flash(struct spinand_device *spinand)
15061516
if (ret)
15071517
return ret;
15081518

1509-
ret = spinand_init_quad_enable(spinand);
1510-
if (ret)
1511-
return ret;
1512-
15131519
ret = spinand_upd_cfg(spinand, CFG_OTP_ENABLE, 0);
15141520
if (ret)
15151521
return ret;
@@ -1522,19 +1528,25 @@ static int spinand_init_flash(struct spinand_device *spinand)
15221528
return ret;
15231529
}
15241530

1531+
ret = spinand_configure_chip(spinand);
1532+
if (ret)
1533+
goto manuf_cleanup;
1534+
15251535
/* After power up, all blocks are locked, so unlock them here. */
15261536
for (i = 0; i < nand->memorg.ntargets; i++) {
15271537
ret = spinand_select_target(spinand, i);
15281538
if (ret)
1529-
break;
1539+
goto manuf_cleanup;
15301540

15311541
ret = spinand_lock_block(spinand, BL_ALL_UNLOCKED);
15321542
if (ret)
1533-
break;
1543+
goto manuf_cleanup;
15341544
}
15351545

1536-
if (ret)
1537-
spinand_manufacturer_cleanup(spinand);
1546+
return 0;
1547+
1548+
manuf_cleanup:
1549+
spinand_manufacturer_cleanup(spinand);
15381550

15391551
return ret;
15401552
}

0 commit comments

Comments
 (0)