linux-mtd.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] mtd: add helpers to set/get features for ONFI nand
@ 2012-09-10  6:01 Huang Shijie
  2012-09-10  6:01 ` [PATCH 2/2] mtd: add helpers to get the supportted ONFI timing mode Huang Shijie
  2012-09-10 16:11 ` [PATCH 1/2] mtd: add helpers to set/get features for ONFI nand Vikram Narayanan
  0 siblings, 2 replies; 4+ messages in thread
From: Huang Shijie @ 2012-09-10  6:01 UTC (permalink / raw)
  To: dwmw2
  Cc: mikedunn, dedekind1, linux-kernel, Huang Shijie, linux-mtd,
	shmulik.ladkani, computersforpeace

Add the set-features(0xef)/get-features(0xee) helpers for ONFI nand.
Also add the necessary macros.

Signed-off-by: Huang Shijie <b32955@freescale.com>
---
 drivers/mtd/nand/nand_base.c |   50 ++++++++++++++++++++++++++++++++++++++++++
 include/linux/mtd/nand.h     |   14 +++++++++++
 2 files changed, 64 insertions(+), 0 deletions(-)

diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c
index 88f671c..fbc49cc 100644
--- a/drivers/mtd/nand/nand_base.c
+++ b/drivers/mtd/nand/nand_base.c
@@ -2700,6 +2700,50 @@ static int nand_block_markbad(struct mtd_info *mtd, loff_t ofs)
 }
 
 /**
+ * nand_onfi_set_features- [REPLACEABLE] set features for ONFI nand
+ * @mtd: MTD device structure
+ * @chip: nand chip info structure
+ * @feature_addr: feature address.
+ * @subfeature_para: the subfeature parameters, a four bytes array.
+ */
+static int nand_onfi_set_features(struct mtd_info *mtd, struct nand_chip *chip,
+			int feature_addr, uint8_t *subfeature_para)
+{
+	int status;
+
+	if (!chip->onfi_version)
+		return -EINVAL;
+
+	chip->cmdfunc(mtd, NAND_CMD_SET_FEATURES, feature_addr, -1);
+	chip->write_buf(mtd, subfeature_para, ONFI_SUBFEATURE_PARA_LEN);
+	status = chip->waitfunc(mtd, chip);
+	if (status & NAND_STATUS_FAIL)
+		return -EIO;
+	return 0;
+}
+
+/**
+ * nand_onfi_get_features- [REPLACEABLE] get features for ONFI nand
+ * @mtd: MTD device structure
+ * @chip: nand chip info structure
+ * @feature_addr: feature address.
+ * @subfeature_para: the subfeature parameters, a four bytes array.
+ */
+static int nand_onfi_get_features(struct mtd_info *mtd, struct nand_chip *chip,
+			int feature_addr, uint8_t *subfeature_para)
+{
+	if (!chip->onfi_version)
+		return -EINVAL;
+
+	/* clear the sub feature parameters */
+	memset(subfeature_para, 0, ONFI_SUBFEATURE_PARA_LEN);
+
+	chip->cmdfunc(mtd, NAND_CMD_GET_FEATURES, feature_addr, -1);
+	chip->read_buf(mtd, subfeature_para, ONFI_SUBFEATURE_PARA_LEN);
+	return 0;
+}
+
+/**
  * nand_suspend - [MTD Interface] Suspend the NAND flash
  * @mtd: MTD device structure
  */
@@ -3223,6 +3267,12 @@ int nand_scan_tail(struct mtd_info *mtd)
 	if (!chip->write_page)
 		chip->write_page = nand_write_page;
 
+	/* set for ONFI nand */
+	if (!chip->onfi_set_features)
+		chip->onfi_set_features = nand_onfi_set_features;
+	if (!chip->onfi_get_features)
+		chip->onfi_get_features = nand_onfi_get_features;
+
 	/*
 	 * Check ECC mode, default to software if 3byte/512byte hardware ECC is
 	 * selected and we have 256 byte pagesize fallback to software ECC
diff --git a/include/linux/mtd/nand.h b/include/linux/mtd/nand.h
index 8f99d36..641794c 100644
--- a/include/linux/mtd/nand.h
+++ b/include/linux/mtd/nand.h
@@ -92,6 +92,8 @@ extern int nand_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len);
 #define NAND_CMD_READID		0x90
 #define NAND_CMD_ERASE2		0xd0
 #define NAND_CMD_PARAM		0xec
+#define NAND_CMD_GET_FEATURES	0xee
+#define NAND_CMD_SET_FEATURES	0xef
 #define NAND_CMD_RESET		0xff
 
 #define NAND_CMD_LOCK		0x2a
@@ -229,6 +231,12 @@ typedef enum {
 /* Keep gcc happy */
 struct nand_chip;
 
+/* ONFI feature address */
+#define ONFI_FEATURE_ADDR_TIMING_MODE	0x1
+
+/* ONFI subfeature parameters length */
+#define ONFI_SUBFEATURE_PARA_LEN	4
+
 struct nand_onfi_params {
 	/* rev info and features block */
 	/* 'O' 'N' 'F' 'I'  */
@@ -452,6 +460,8 @@ struct nand_buffers {
  *			non 0 if ONFI supported.
  * @onfi_params:	[INTERN] holds the ONFI page parameter when ONFI is
  *			supported, 0 otherwise.
+ * @onfi_set_features	[REPLACEABLE] set the features for ONFI nand
+ * @onfi_get_features	[REPLACEABLE] get the features for ONFI nand
  * @ecclayout:		[REPLACEABLE] the default ECC placement scheme
  * @bbt:		[INTERN] bad block table pointer
  * @bbt_td:		[REPLACEABLE] bad block table descriptor for flash
@@ -494,6 +504,10 @@ struct nand_chip {
 	int (*write_page)(struct mtd_info *mtd, struct nand_chip *chip,
 			const uint8_t *buf, int oob_required, int page,
 			int cached, int raw);
+	int (*onfi_set_features)(struct mtd_info *mtd, struct nand_chip *chip,
+			int feature_addr, uint8_t *subfeature_para);
+	int (*onfi_get_features)(struct mtd_info *mtd, struct nand_chip *chip,
+			int feature_addr, uint8_t *subfeature_para);
 
 	int chip_delay;
 	unsigned int options;
-- 
1.7.0.4

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/2] mtd: add helpers to get the supportted ONFI timing mode
  2012-09-10  6:01 [PATCH 1/2] mtd: add helpers to set/get features for ONFI nand Huang Shijie
@ 2012-09-10  6:01 ` Huang Shijie
  2012-09-10 16:11 ` [PATCH 1/2] mtd: add helpers to set/get features for ONFI nand Vikram Narayanan
  1 sibling, 0 replies; 4+ messages in thread
From: Huang Shijie @ 2012-09-10  6:01 UTC (permalink / raw)
  To: dwmw2
  Cc: mikedunn, dedekind1, linux-kernel, Huang Shijie, linux-mtd,
	shmulik.ladkani, computersforpeace

add onfi_get_async_timing_mode() to get the supportted asynchronous
timing mode.

add onfi_get_sync_timing_mode() to get the supportted synchronous
timing mode.

Also add the neccessary macros : the timing modes.

Signed-off-by: Huang Shijie <b32955@freescale.com>
---
 include/linux/mtd/nand.h |   20 ++++++++++++++++++++
 1 files changed, 20 insertions(+), 0 deletions(-)

diff --git a/include/linux/mtd/nand.h b/include/linux/mtd/nand.h
index 641794c..83b85a1 100644
--- a/include/linux/mtd/nand.h
+++ b/include/linux/mtd/nand.h
@@ -231,6 +231,14 @@ typedef enum {
 /* Keep gcc happy */
 struct nand_chip;
 
+/* ONFI timing mode, used in both asynchronous and synchronous mode */
+#define ONFI_TIMING_MODE_0	(1 << 0)
+#define ONFI_TIMING_MODE_1	(1 << 1)
+#define ONFI_TIMING_MODE_2	(1 << 2)
+#define ONFI_TIMING_MODE_3	(1 << 3)
+#define ONFI_TIMING_MODE_4	(1 << 4)
+#define ONFI_TIMING_MODE_5	(1 << 5)
+
 /* ONFI feature address */
 #define ONFI_FEATURE_ADDR_TIMING_MODE	0x1
 
@@ -682,4 +690,16 @@ struct platform_nand_chip *get_platform_nandchip(struct mtd_info *mtd)
 	return chip->priv;
 }
 
+/* return the supported asynchronous timing mode. */
+static inline int onfi_get_async_timing_mode(struct nand_chip *chip)
+{
+	return le16_to_cpu(chip->onfi_params.async_timing_mode);
+}
+
+/* return the supported synchronous timing mode. */
+static inline int onfi_get_sync_timing_mode(struct nand_chip *chip)
+{
+	return le16_to_cpu(chip->onfi_params.src_sync_timing_mode);
+}
+
 #endif /* __LINUX_MTD_NAND_H */
-- 
1.7.0.4

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 1/2] mtd: add helpers to set/get features for ONFI nand
  2012-09-10  6:01 [PATCH 1/2] mtd: add helpers to set/get features for ONFI nand Huang Shijie
  2012-09-10  6:01 ` [PATCH 2/2] mtd: add helpers to get the supportted ONFI timing mode Huang Shijie
@ 2012-09-10 16:11 ` Vikram Narayanan
  2012-09-11  1:59   ` Huang Shijie
  1 sibling, 1 reply; 4+ messages in thread
From: Vikram Narayanan @ 2012-09-10 16:11 UTC (permalink / raw)
  To: Huang Shijie; +Cc: linux-mtd, dedekind1

Hello Huang Shijie,

<Dropped cc's>

Just a few nitpicks.

On 9/10/2012 11:31 AM, Huang Shijie wrote:
> Add the set-features(0xef)/get-features(0xee) helpers for ONFI nand.
> Also add the necessary macros.
>
> Signed-off-by: Huang Shijie<b32955@freescale.com>
> ---
>   drivers/mtd/nand/nand_base.c |   50 ++++++++++++++++++++++++++++++++++++++++++
>   include/linux/mtd/nand.h     |   14 +++++++++++
>   2 files changed, 64 insertions(+), 0 deletions(-)
>
> diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c
> index 88f671c..fbc49cc 100644
> --- a/drivers/mtd/nand/nand_base.c
> +++ b/drivers/mtd/nand/nand_base.c
> @@ -2700,6 +2700,50 @@ static int nand_block_markbad(struct mtd_info *mtd, loff_t ofs)
>   }
>
>   /**
> + * nand_onfi_set_features- [REPLACEABLE] set features for ONFI nand
> + * @mtd: MTD device structure
> + * @chip: nand chip info structure
> + * @feature_addr: feature address.

As the function conveys that you're setting/getting the features, may be 
you can drop the prefix from the above addr. Just a thought.

> + * @subfeature_para: the subfeature parameters, a four bytes array.

subfeature_param should be more appropriate.

> + */
> +static int nand_onfi_set_features(struct mtd_info *mtd, struct nand_chip *chip,
> +			int feature_addr, uint8_t *subfeature_para)
> +{
> +	int status;
> +
> +	if (!chip->onfi_version)
> +		return -EINVAL;
> +
> +	chip->cmdfunc(mtd, NAND_CMD_SET_FEATURES, feature_addr, -1);
> +	chip->write_buf(mtd, subfeature_para, ONFI_SUBFEATURE_PARA_LEN);

							^ PARAM_LEN here

> +	status = chip->waitfunc(mtd, chip);
> +	if (status&  NAND_STATUS_FAIL)
> +		return -EIO;
> +	return 0;
> +}
> +
> +/**
> + * nand_onfi_get_features- [REPLACEABLE] get features for ONFI nand
> + * @mtd: MTD device structure
> + * @chip: nand chip info structure
> + * @feature_addr: feature address.
> + * @subfeature_para: the subfeature parameters, a four bytes array.
> + */
> +static int nand_onfi_get_features(struct mtd_info *mtd, struct nand_chip *chip,
> +			int feature_addr, uint8_t *subfeature_para)
> +{
> +	if (!chip->onfi_version)
> +		return -EINVAL;
> +
> +	/* clear the sub feature parameters */
> +	memset(subfeature_para, 0, ONFI_SUBFEATURE_PARA_LEN);
> +
> +	chip->cmdfunc(mtd, NAND_CMD_GET_FEATURES, feature_addr, -1);
> +	chip->read_buf(mtd, subfeature_para, ONFI_SUBFEATURE_PARA_LEN);
> +	return 0;
> +}
> +
> +/**
>    * nand_suspend - [MTD Interface] Suspend the NAND flash
>    * @mtd: MTD device structure
>    */
> @@ -3223,6 +3267,12 @@ int nand_scan_tail(struct mtd_info *mtd)
>   	if (!chip->write_page)
>   		chip->write_page = nand_write_page;
>
> +	/* set for ONFI nand */
> +	if (!chip->onfi_set_features)
> +		chip->onfi_set_features = nand_onfi_set_features;
> +	if (!chip->onfi_get_features)
> +		chip->onfi_get_features = nand_onfi_get_features;
> +
>   	/*
>   	 * Check ECC mode, default to software if 3byte/512byte hardware ECC is
>   	 * selected and we have 256 byte pagesize fallback to software ECC
> diff --git a/include/linux/mtd/nand.h b/include/linux/mtd/nand.h
> index 8f99d36..641794c 100644
> --- a/include/linux/mtd/nand.h
> +++ b/include/linux/mtd/nand.h
> @@ -92,6 +92,8 @@ extern int nand_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len);
>   #define NAND_CMD_READID		0x90
>   #define NAND_CMD_ERASE2		0xd0
>   #define NAND_CMD_PARAM		0xec
> +#define NAND_CMD_GET_FEATURES	0xee
> +#define NAND_CMD_SET_FEATURES	0xef
>   #define NAND_CMD_RESET		0xff
>
>   #define NAND_CMD_LOCK		0x2a
> @@ -229,6 +231,12 @@ typedef enum {
>   /* Keep gcc happy */
>   struct nand_chip;
>
> +/* ONFI feature address */
> +#define ONFI_FEATURE_ADDR_TIMING_MODE	0x1
> +
> +/* ONFI subfeature parameters length */
> +#define ONFI_SUBFEATURE_PARA_LEN	4

PARAM_LEN

> +
>   struct nand_onfi_params {
>   	/* rev info and features block */
>   	/* 'O' 'N' 'F' 'I'  */
> @@ -452,6 +460,8 @@ struct nand_buffers {
>    *			non 0 if ONFI supported.
>    * @onfi_params:	[INTERN] holds the ONFI page parameter when ONFI is
>    *			supported, 0 otherwise.
> + * @onfi_set_features	[REPLACEABLE] set the features for ONFI nand
> + * @onfi_get_features	[REPLACEABLE] get the features for ONFI nand
>    * @ecclayout:		[REPLACEABLE] the default ECC placement scheme
>    * @bbt:		[INTERN] bad block table pointer
>    * @bbt_td:		[REPLACEABLE] bad block table descriptor for flash
> @@ -494,6 +504,10 @@ struct nand_chip {
>   	int (*write_page)(struct mtd_info *mtd, struct nand_chip *chip,
>   			const uint8_t *buf, int oob_required, int page,
>   			int cached, int raw);
> +	int (*onfi_set_features)(struct mtd_info *mtd, struct nand_chip *chip,
> +			int feature_addr, uint8_t *subfeature_para);
> +	int (*onfi_get_features)(struct mtd_info *mtd, struct nand_chip *chip,
> +			int feature_addr, uint8_t *subfeature_para);
>
>   	int chip_delay;
>   	unsigned int options;


Regards,
Vikram

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 1/2] mtd: add helpers to set/get features for ONFI nand
  2012-09-10 16:11 ` [PATCH 1/2] mtd: add helpers to set/get features for ONFI nand Vikram Narayanan
@ 2012-09-11  1:59   ` Huang Shijie
  0 siblings, 0 replies; 4+ messages in thread
From: Huang Shijie @ 2012-09-11  1:59 UTC (permalink / raw)
  To: Vikram Narayanan; +Cc: linux-mtd, dedekind1

于 2012年09月11日 00:11, Vikram Narayanan 写道:
> Hello Huang Shijie,
>
> <Dropped cc's>
>
> Just a few nitpicks.
>
> On 9/10/2012 11:31 AM, Huang Shijie wrote:
>> Add the set-features(0xef)/get-features(0xee) helpers for ONFI nand.
>> Also add the necessary macros.
>>
>> Signed-off-by: Huang Shijie<b32955@freescale.com>
>> ---
>> drivers/mtd/nand/nand_base.c | 50 
>> ++++++++++++++++++++++++++++++++++++++++++
>> include/linux/mtd/nand.h | 14 +++++++++++
>> 2 files changed, 64 insertions(+), 0 deletions(-)
>>
>> diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c
>> index 88f671c..fbc49cc 100644
>> --- a/drivers/mtd/nand/nand_base.c
>> +++ b/drivers/mtd/nand/nand_base.c
>> @@ -2700,6 +2700,50 @@ static int nand_block_markbad(struct mtd_info 
>> *mtd, loff_t ofs)
>> }
>>
>> /**
>> + * nand_onfi_set_features- [REPLACEABLE] set features for ONFI nand
>> + * @mtd: MTD device structure
>> + * @chip: nand chip info structure
>> + * @feature_addr: feature address.
>
> As the function conveys that you're setting/getting the features, may 
> be you can drop the prefix from the above addr. Just a thought.
>
>> + * @subfeature_para: the subfeature parameters, a four bytes array.
>
> subfeature_param should be more appropriate.
>
>> + */
>> +static int nand_onfi_set_features(struct mtd_info *mtd, struct 
>> nand_chip *chip,
>> + int feature_addr, uint8_t *subfeature_para)
>> +{
>> + int status;
>> +
>> + if (!chip->onfi_version)
>> + return -EINVAL;
>> +
>> + chip->cmdfunc(mtd, NAND_CMD_SET_FEATURES, feature_addr, -1);
>> + chip->write_buf(mtd, subfeature_para, ONFI_SUBFEATURE_PARA_LEN);
>
> ^ PARAM_LEN here
>
>> + status = chip->waitfunc(mtd, chip);
>> + if (status& NAND_STATUS_FAIL)
>> + return -EIO;
>> + return 0;
>> +}
>> +
>> +/**
>> + * nand_onfi_get_features- [REPLACEABLE] get features for ONFI nand
>> + * @mtd: MTD device structure
>> + * @chip: nand chip info structure
>> + * @feature_addr: feature address.
>> + * @subfeature_para: the subfeature parameters, a four bytes array.
>> + */
>> +static int nand_onfi_get_features(struct mtd_info *mtd, struct 
>> nand_chip *chip,
>> + int feature_addr, uint8_t *subfeature_para)
>> +{
>> + if (!chip->onfi_version)
>> + return -EINVAL;
>> +
>> + /* clear the sub feature parameters */
>> + memset(subfeature_para, 0, ONFI_SUBFEATURE_PARA_LEN);
>> +
>> + chip->cmdfunc(mtd, NAND_CMD_GET_FEATURES, feature_addr, -1);
>> + chip->read_buf(mtd, subfeature_para, ONFI_SUBFEATURE_PARA_LEN);
>> + return 0;
>> +}
>> +
>> +/**
>> * nand_suspend - [MTD Interface] Suspend the NAND flash
>> * @mtd: MTD device structure
>> */
>> @@ -3223,6 +3267,12 @@ int nand_scan_tail(struct mtd_info *mtd)
>> if (!chip->write_page)
>> chip->write_page = nand_write_page;
>>
>> + /* set for ONFI nand */
>> + if (!chip->onfi_set_features)
>> + chip->onfi_set_features = nand_onfi_set_features;
>> + if (!chip->onfi_get_features)
>> + chip->onfi_get_features = nand_onfi_get_features;
>> +
>> /*
>> * Check ECC mode, default to software if 3byte/512byte hardware ECC is
>> * selected and we have 256 byte pagesize fallback to software ECC
>> diff --git a/include/linux/mtd/nand.h b/include/linux/mtd/nand.h
>> index 8f99d36..641794c 100644
>> --- a/include/linux/mtd/nand.h
>> +++ b/include/linux/mtd/nand.h
>> @@ -92,6 +92,8 @@ extern int nand_unlock(struct mtd_info *mtd, loff_t 
>> ofs, uint64_t len);
>> #define NAND_CMD_READID 0x90
>> #define NAND_CMD_ERASE2 0xd0
>> #define NAND_CMD_PARAM 0xec
>> +#define NAND_CMD_GET_FEATURES 0xee
>> +#define NAND_CMD_SET_FEATURES 0xef
>> #define NAND_CMD_RESET 0xff
>>
>> #define NAND_CMD_LOCK 0x2a
>> @@ -229,6 +231,12 @@ typedef enum {
>> /* Keep gcc happy */
>> struct nand_chip;
>>
>> +/* ONFI feature address */
>> +#define ONFI_FEATURE_ADDR_TIMING_MODE 0x1
>> +
>> +/* ONFI subfeature parameters length */
>> +#define ONFI_SUBFEATURE_PARA_LEN 4
>
> PARAM_LEN
>
>> +
>> struct nand_onfi_params {
>> /* rev info and features block */
>> /* 'O' 'N' 'F' 'I' */
>> @@ -452,6 +460,8 @@ struct nand_buffers {
>> * non 0 if ONFI supported.
>> * @onfi_params: [INTERN] holds the ONFI page parameter when ONFI is
>> * supported, 0 otherwise.
>> + * @onfi_set_features [REPLACEABLE] set the features for ONFI nand
>> + * @onfi_get_features [REPLACEABLE] get the features for ONFI nand
>> * @ecclayout: [REPLACEABLE] the default ECC placement scheme
>> * @bbt: [INTERN] bad block table pointer
>> * @bbt_td: [REPLACEABLE] bad block table descriptor for flash
>> @@ -494,6 +504,10 @@ struct nand_chip {
>> int (*write_page)(struct mtd_info *mtd, struct nand_chip *chip,
>> const uint8_t *buf, int oob_required, int page,
>> int cached, int raw);
>> + int (*onfi_set_features)(struct mtd_info *mtd, struct nand_chip *chip,
>> + int feature_addr, uint8_t *subfeature_para);
>> + int (*onfi_get_features)(struct mtd_info *mtd, struct nand_chip *chip,
>> + int feature_addr, uint8_t *subfeature_para);
>>
>> int chip_delay;
>> unsigned int options;
>
thanks a lot for the review.

I will change them in the next version.

Best Regards
Huang Shijie

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2012-09-11  1:56 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-09-10  6:01 [PATCH 1/2] mtd: add helpers to set/get features for ONFI nand Huang Shijie
2012-09-10  6:01 ` [PATCH 2/2] mtd: add helpers to get the supportted ONFI timing mode Huang Shijie
2012-09-10 16:11 ` [PATCH 1/2] mtd: add helpers to set/get features for ONFI nand Vikram Narayanan
2012-09-11  1:59   ` Huang Shijie

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).