linux-mtd.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: Miquel Raynal <miquel.raynal@bootlin.com>
To: Mason Yang <masonccyang@mxic.com.tw>
Cc: vigneshr@ti.com, bbrezillon@kernel.org, juliensu@mxic.com.tw,
	richard@nod.at, linux-kernel@vger.kernel.org,
	marek.vasut@gmail.com, linux-mtd@lists.infradead.org,
	computersforpeace@gmail.com, dwmw2@infradead.org
Subject: Re: [PATCH v2 4/4] mtd: rawnand: Add support Macronix deep power down mode
Date: Thu, 9 Jan 2020 18:01:28 +0100	[thread overview]
Message-ID: <20200109180128.0f3e7b99@xps13> (raw)
In-Reply-To: <1572256527-5074-5-git-send-email-masonccyang@mxic.com.tw>

Hi Mason,

Mason Yang <masonccyang@mxic.com.tw> wrote on Mon, 28 Oct 2019 17:55:27
+0800:

> Macronix AD series support deep power down mode for a minimum
> power consumption state.
> 
> Patch nand_suspend() & nand_resume() by Macronix specific
> deep power down mode command and exit it.
> 
> Signed-off-by: Mason Yang <masonccyang@mxic.com.tw>
> ---
>  drivers/mtd/nand/raw/nand_macronix.c | 72 +++++++++++++++++++++++++++++++++++-
>  1 file changed, 70 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/mtd/nand/raw/nand_macronix.c b/drivers/mtd/nand/raw/nand_macronix.c
> index 13929bf..3098bc0 100644
> --- a/drivers/mtd/nand/raw/nand_macronix.c
> +++ b/drivers/mtd/nand/raw/nand_macronix.c
> @@ -15,6 +15,8 @@
>  #define MXIC_BLOCK_PROTECTION_ALL_LOCK 0x38
>  #define MXIC_BLOCK_PROTECTION_ALL_UNLOCK 0x0
>  
> +#define NAND_CMD_POWER_DOWN 0xB9

I suppose this value is Macronix specific, and hence should have a
MACRONIX_ or MXIC_ prefix instead of NAND_.

> +
>  struct nand_onfi_vendor_macronix {
>  	u8 reserved;
>  	u8 reliability_func;
> @@ -137,13 +139,66 @@ static int mxic_nand_unlock(struct nand_chip *chip, loff_t ofs, uint64_t len)
>  	return ret;
>  }
>  
> +int nand_power_down_op(struct nand_chip *chip)
> +{
> +	int ret;
> +
> +	if (nand_has_exec_op(chip)) {
> +		struct nand_op_instr instrs[] = {
> +			NAND_OP_CMD(NAND_CMD_POWER_DOWN, 0),
> +		};
> +
> +		struct nand_operation op = NAND_OPERATION(chip->cur_cs, instrs);
> +
> +		ret = nand_exec_op(chip, &op);
> +		if (ret)
> +			return ret;
> +
> +	} else {
> +		chip->legacy.cmdfunc(chip, NAND_CMD_POWER_DOWN, -1, -1);
> +	}
> +
> +	return 0;
> +}
> +
> +static int mxic_nand_suspend(struct nand_chip *chip)
> +{
> +	int ret;
> +
> +	nand_select_target(chip, 0);
> +	ret = nand_power_down_op(chip);
> +	if (ret < 0)
> +		pr_err("%s called for chip into suspend failed\n", __func__);

What about something more specific?

       "Suspending MXIC NAND chip failed (%)\n", ret

> +	nand_deselect_target(chip);
> +
> +	return ret;
> +}
> +
> +static void mxic_nand_resume(struct nand_chip *chip)
> +{
> +	/*
> +	 * Toggle #CS pin to resume NAND device and don't care
> +	 * of the others CLE, #WE, #RE pins status.
> +	 * Here sending power down command to toggle #CS line.

The first sentence seems right, the second could be upgraded:

           The purpose of doing a power down operation is just to
           ensure some bytes will be sent over the NAND bus so that #CS
           gets toggled because this is why the chip is woken up.
	   The content of the bytes sent on the NAND bus are not
	   relevant at this time. Sending bytes on the bus is mandatory
	   for a lot of NAND controllers otherwise they are not able to
	   just assert/de-assert #CS.

> +	 */
> +	nand_select_target(chip, 0);
> +	nand_power_down_op(chip);

Are you sure sending a power_down_op will not be interpreted by the
chip?

I would expect a sleeping delay here, even small.

> +	nand_deselect_target(chip);
> +}
> +
>  /*
> - * Macronix NAND AC series support Block Protection by SET_FEATURES
> + * Macronix NAND AC & AD series support Block Protection by SET_FEATURES
>   * to lock/unlock blocks.
>   */
>  static int macronix_nand_init(struct nand_chip *chip)
>  {
> -	bool blockprotected = false;
> +	unsigned int i;
> +	bool blockprotected = false, powerdown = false;
> +	static const char * const power_down_dev[] = {
> +		"MX30LF1G28AD",
> +		"MX30LF2G28AD",
> +		"MX30LF4G28AD",
> +	};
>  
>  	if (nand_is_slc(chip))
>  		chip->options |= NAND_BBM_FIRSTPAGE | NAND_BBM_SECONDPAGE;
> @@ -153,6 +208,14 @@ static int macronix_nand_init(struct nand_chip *chip)
>  
>  	macronix_nand_onfi_init(chip);
>  
> +	for (i = 0; i < ARRAY_SIZE(power_down_dev); i++) {
> +		if (!strcmp(power_down_dev[i], chip->parameters.model)) {
> +			blockprotected = true;
> +			powerdown = true;
> +			break;
> +		}
> +	}
> +
>  	if (blockprotected) {
>  		bitmap_set(chip->parameters.set_feature_list,
>  			   ONFI_FEATURE_ADDR_MXIC_PROTECTION, 1);
> @@ -163,6 +226,11 @@ static int macronix_nand_init(struct nand_chip *chip)
>  		chip->_unlock = mxic_nand_unlock;
>  	}
>  
> +	if (powerdown) {
> +		chip->_suspend = mxic_nand_suspend;
> +		chip->_resume = mxic_nand_resume;
> +	}

See my comment on patch 2.

> +
>  	return 0;
>  }
>  

Thanks,
Miquèl

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

  parent reply	other threads:[~2020-01-09 17:01 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-28  9:55 [PATCH v2 0/4] mtd: rawnand: Add support Macronix Block Protection & deep power down mode Mason Yang
2019-10-28  9:55 ` [PATCH v2 1/4] mtd: rawnand: Add support manufacturer specific lock/unlock operatoin Mason Yang
2019-10-30  3:22   ` kbuild test robot
2020-01-09 16:41   ` Miquel Raynal
2020-02-17  8:05     ` masonccyang
2020-01-09 19:30   ` Boris Brezillon
2020-02-17  8:14     ` masonccyang
2020-02-17  9:01       ` Miquel Raynal
2020-02-17  9:22         ` Boris Brezillon
2020-02-18  3:13         ` masonccyang
2019-10-28  9:55 ` [PATCH v2 2/4] mtd: rawnand: Add support Macronix Block Protection function Mason Yang
2020-01-09 16:47   ` Miquel Raynal
2020-02-17  8:24     ` masonccyang
2019-10-28  9:55 ` [PATCH v2 3/4] mtd: rawnand: Add support manufacturer specific suspend/resume operation Mason Yang
2019-10-30  5:56   ` kbuild test robot
2020-01-09 16:53   ` Miquel Raynal
2019-10-28  9:55 ` [PATCH v2 4/4] mtd: rawnand: Add support Macronix deep power down mode Mason Yang
2019-10-31  7:36   ` kbuild test robot
2019-10-31  7:36   ` [RFC PATCH] mtd: rawnand: nand_power_down_op() can be static kbuild test robot
2020-01-09 17:01   ` Miquel Raynal [this message]
2020-02-21  2:44     ` [PATCH v2 4/4] mtd: rawnand: Add support Macronix deep power down mode masonccyang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200109180128.0f3e7b99@xps13 \
    --to=miquel.raynal@bootlin.com \
    --cc=bbrezillon@kernel.org \
    --cc=computersforpeace@gmail.com \
    --cc=dwmw2@infradead.org \
    --cc=juliensu@mxic.com.tw \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mtd@lists.infradead.org \
    --cc=marek.vasut@gmail.com \
    --cc=masonccyang@mxic.com.tw \
    --cc=richard@nod.at \
    --cc=vigneshr@ti.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).