Patchwork nand_base: fix for ONFI chips that do not support GET/SET FEATURES

login
register
mail settings
Submitter David Mosberger-Tang
Date May 2, 2013, 3:45 a.m.
Message ID <CACwUX0ObapqNuV=D_8nMT6Pbr-PQhkC=ZfuVMWEOtGUcyzt8tg@mail.gmail.com>
Download mbox | patch
Permalink /patch/240890/
State New
Headers show

Comments

David Mosberger-Tang - May 2, 2013, 3:45 a.m.
Fine by me.

  --david


On Wed, May 1, 2013 at 8:41 PM, Huang Shijie <b32955@freescale.com> wrote:
> 于 2013年05月02日 10:34, David Mosberger-Tang 写道:
>> +         !(le16_to_cpu(chip->onfi_params.opt_cmd) & 4))
> it's better to add a macro to replace the hardcore '4', such as
>
> #define ONFI_OPT_CMD_SET_GET_FEAT (1 << 2)
>
> Just a suggestion. :)
>
> thanks
> Huang Shijie
>

Patch

diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c
index dfcd0a5..db31357 100644
--- a/drivers/mtd/nand/nand_base.c
+++ b/drivers/mtd/nand/nand_base.c
@@ -2720,7 +2720,8 @@  static int nand_onfi_set_features(struct mtd_info *mtd, struct nand_chip *chip,
 {
 	int status;
 
-	if (!chip->onfi_version)
+	if (!chip->onfi_version ||
+	    !(le16_to_cpu(chip->onfi_params.opt_cmd) & ONFI_OPT_CMD_SET_GET_FEATURES))
 		return -EINVAL;
 
 	chip->cmdfunc(mtd, NAND_CMD_SET_FEATURES, addr, -1);
@@ -2741,7 +2742,8 @@  static int nand_onfi_set_features(struct mtd_info *mtd, struct nand_chip *chip,
 static int nand_onfi_get_features(struct mtd_info *mtd, struct nand_chip *chip,
 			int addr, uint8_t *subfeature_param)
 {
-	if (!chip->onfi_version)
+	if (!chip->onfi_version ||
+	    !(le16_to_cpu(chip->onfi_params.opt_cmd) & ONFI_OPT_CMD_SET_GET_FEATURES))
 		return -EINVAL;
 
 	/* clear the sub feature parameters */
diff --git a/include/linux/mtd/nand.h b/include/linux/mtd/nand.h
index ab63634..9b98af8 100644
--- a/include/linux/mtd/nand.h
+++ b/include/linux/mtd/nand.h
@@ -217,6 +217,9 @@  struct nand_chip;
 /* ONFI subfeature parameters length */
 #define ONFI_SUBFEATURE_PARAM_LEN	4
 
+/* ONFI optional commands SET/GET FEATURES supported? */
+#define ONFI_OPT_CMD_SET_GET_FEATURES	(1 << 2)
+
 struct nand_onfi_params {
 	/* rev info and features block */
 	/* 'O' 'N' 'F' 'I'  */