Skip to content

Commit f6ca3fb

Browse files
Emantormiquelraynal
authored andcommitted
mtd: rawnand: Ensure the nand chip supports cached reads
Both the JEDEC and ONFI specification say that read cache sequential support is an optional command. This means that we not only need to check whether the individual controller supports the command, we also need to check the parameter pages for both ONFI and JEDEC NAND flashes before enabling sequential cache reads. This fixes support for NAND flashes which don't support enabling cache reads, i.e. Samsung K9F4G08U0F or Toshiba TC58NVG0S3HTA00. Sequential cache reads are now only available for ONFI and JEDEC devices, if individual vendors implement this, it needs to be enabled per vendor. Tested on i.MX6Q with a Samsung NAND flash chip that doesn't support sequential reads. Fixes: 003fe4b ("mtd: rawnand: Support for sequential cache reads") Cc: [email protected] Signed-off-by: Rouven Czerwinski <[email protected]> Signed-off-by: Miquel Raynal <[email protected]> Link: https://lore.kernel.org/linux-mtd/[email protected]
1 parent 5279f4a commit f6ca3fb

File tree

6 files changed

+15
-0
lines changed

6 files changed

+15
-0
lines changed

drivers/mtd/nand/raw/nand_base.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5110,6 +5110,9 @@ static void rawnand_check_cont_read_support(struct nand_chip *chip)
51105110
{
51115111
struct mtd_info *mtd = nand_to_mtd(chip);
51125112

5113+
if (!chip->parameters.supports_read_cache)
5114+
return;
5115+
51135116
if (chip->read_retries)
51145117
return;
51155118

drivers/mtd/nand/raw/nand_jedec.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@ int nand_jedec_detect(struct nand_chip *chip)
9494
goto free_jedec_param_page;
9595
}
9696

97+
if (p->opt_cmd[0] & JEDEC_OPT_CMD_READ_CACHE)
98+
chip->parameters.supports_read_cache = true;
99+
97100
memorg->pagesize = le32_to_cpu(p->byte_per_page);
98101
mtd->writesize = memorg->pagesize;
99102

drivers/mtd/nand/raw/nand_onfi.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,9 @@ int nand_onfi_detect(struct nand_chip *chip)
303303
ONFI_FEATURE_ADDR_TIMING_MODE, 1);
304304
}
305305

306+
if (le16_to_cpu(p->opt_cmd) & ONFI_OPT_CMD_READ_CACHE)
307+
chip->parameters.supports_read_cache = true;
308+
306309
onfi = kzalloc(sizeof(*onfi), GFP_KERNEL);
307310
if (!onfi) {
308311
ret = -ENOMEM;

include/linux/mtd/jedec.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ struct jedec_ecc_info {
2121
/* JEDEC features */
2222
#define JEDEC_FEATURE_16_BIT_BUS (1 << 0)
2323

24+
/* JEDEC Optional Commands */
25+
#define JEDEC_OPT_CMD_READ_CACHE BIT(1)
26+
2427
struct nand_jedec_params {
2528
/* rev info and features block */
2629
/* 'J' 'E' 'S' 'D' */

include/linux/mtd/onfi.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
#define ONFI_SUBFEATURE_PARAM_LEN 4
5656

5757
/* ONFI optional commands SET/GET FEATURES supported? */
58+
#define ONFI_OPT_CMD_READ_CACHE BIT(1)
5859
#define ONFI_OPT_CMD_SET_GET_FEATURES BIT(2)
5960

6061
struct nand_onfi_params {

include/linux/mtd/rawnand.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ struct gpio_desc;
225225
* struct nand_parameters - NAND generic parameters from the parameter page
226226
* @model: Model name
227227
* @supports_set_get_features: The NAND chip supports setting/getting features
228+
* @supports_read_cache: The NAND chip supports read cache operations
228229
* @set_feature_list: Bitmap of features that can be set
229230
* @get_feature_list: Bitmap of features that can be get
230231
* @onfi: ONFI specific parameters
@@ -233,6 +234,7 @@ struct nand_parameters {
233234
/* Generic parameters */
234235
const char *model;
235236
bool supports_set_get_features;
237+
bool supports_read_cache;
236238
DECLARE_BITMAP(set_feature_list, ONFI_FEATURE_NUMBER);
237239
DECLARE_BITMAP(get_feature_list, ONFI_FEATURE_NUMBER);
238240

0 commit comments

Comments
 (0)