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: juliensu@mxic.com.tw, vigneshr@ti.com, bbrezillon@kernel.org,
	marcel.ziswiler@toradex.com, richard@nod.at,
	linux-kernel@vger.kernel.org, frieder.schrempf@kontron.de,
	marek.vasut@gmail.com, linux-mtd@lists.infradead.org,
	gregkh@linuxfoundation.org, tglx@linutronix.de,
	computersforpeace@gmail.com, dwmw2@infradead.org
Subject: Re: [PATCH RFC 2/3] mtd: rawnand: Add support Macronix Block Protection function
Date: Mon, 7 Oct 2019 10:45:11 +0200	[thread overview]
Message-ID: <20191007104511.5aa7b8f2@xps13> (raw)
In-Reply-To: <1568793387-25199-2-git-send-email-masonccyang@mxic.com.tw>

Hi Mason,

Mason Yang <masonccyang@mxic.com.tw> wrote on Wed, 18 Sep 2019 15:56:25
+0800:

> Macronix AC series support using SET/GET_FEATURES to change
> Block Protection and Unprotection.
> 
> MTD default _lock/_unlock function replacement by manufacturer
> postponed initialization.

Why would we do that?

Anyway your solution looks overkill, if we ever decide to
implement these hooks for raw nand, it is better just to not
overwrite them in nand_scan_tail() if they have been filled
previously (ie. by the manufacturer code).

> Signed-off-by: Mason Yang <masonccyang@mxic.com.tw>
> ---
>  drivers/mtd/nand/raw/nand_macronix.c | 80 +++++++++++++++++++++++++++++++++---
>  1 file changed, 75 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/mtd/nand/raw/nand_macronix.c b/drivers/mtd/nand/raw/nand_macronix.c
> index 58511ae..991c636 100644
> --- a/drivers/mtd/nand/raw/nand_macronix.c
> +++ b/drivers/mtd/nand/raw/nand_macronix.c
> @@ -11,6 +11,10 @@
>  #define MACRONIX_READ_RETRY_BIT BIT(0)
>  #define MACRONIX_NUM_READ_RETRY_MODES 6
>  
> +#define ONFI_FEATURE_ADDR_MXIC_PROTECTION 0xA0
> +#define MXIC_BLOCK_PROTECTION_ALL_LOCK 0x38
> +#define MXIC_BLOCK_PROTECTION_ALL_UNLOCK 0x0
> +
>  struct nand_onfi_vendor_macronix {
>  	u8 reserved;
>  	u8 reliability_func;
> @@ -57,10 +61,7 @@ static void macronix_nand_onfi_init(struct nand_chip *chip)
>   * the timings unlike what is declared in the parameter page. Unflag
>   * this feature to avoid unnecessary downturns.
>   */
> -static void macronix_nand_fix_broken_get_timings(struct nand_chip *chip)
> -{
> -	unsigned int i;
> -	static const char * const broken_get_timings[] = {
> +static const char * const broken_get_timings[] = {
>  		"MX30LF1G18AC",
>  		"MX30LF1G28AC",
>  		"MX30LF2G18AC",
> @@ -75,7 +76,11 @@ static void macronix_nand_fix_broken_get_timings(struct nand_chip *chip)
>  		"MX30UF4G18AC",
>  		"MX30UF4G16AC",
>  		"MX30UF4G28AC",
> -	};
> +};
> +
> +static void macronix_nand_fix_broken_get_timings(struct nand_chip *chip)
> +{
> +	unsigned int i;
>  
>  	if (!chip->parameters.supports_set_get_features)
>  		return;
> @@ -105,6 +110,71 @@ static int macronix_nand_init(struct nand_chip *chip)
>  	return 0;
>  }
>  
> +static int mxic_nand_lock(struct mtd_info *mtd, loff_t ofs, uint64_t len)
> +{
> +	struct nand_chip *chip = mtd_to_nand(mtd);
> +	u8 feature[ONFI_SUBFEATURE_PARAM_LEN];
> +	int ret;
> +
> +	feature[0] = MXIC_BLOCK_PROTECTION_ALL_LOCK;
> +	nand_select_target(chip, 0);
> +	ret = nand_set_features(chip, ONFI_FEATURE_ADDR_MXIC_PROTECTION,
> +				feature);
> +	nand_deselect_target(chip);
> +	if (ret)
> +		pr_err("%s all blocks failed\n", __func__);
> +
> +	return ret;
> +}
> +
> +static int mxic_nand_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len)
> +{
> +	struct nand_chip *chip = mtd_to_nand(mtd);
> +	u8 feature[ONFI_SUBFEATURE_PARAM_LEN];
> +	int ret;
> +
> +	feature[0] = MXIC_BLOCK_PROTECTION_ALL_UNLOCK;
> +	nand_select_target(chip, 0);
> +	ret = nand_set_features(chip, ONFI_FEATURE_ADDR_MXIC_PROTECTION,
> +				feature);
> +	nand_deselect_target(chip);
> +	if (ret)
> +		pr_err("%s all blocks failed\n", __func__);
> +
> +	return ret;
> +}
> +
> +/*
> + * Macronix AC series support using SET/GET_FEATURES to change
> + * Block Protection and Unprotection.
> + *
> + * MTD call-back function replacement by manufacturer postponed
> + * initialization.
> + */
> +static void macronix_nand_post_init(struct nand_chip *chip)
> +{
> +	unsigned int i, blockprotected = 0;
> +	struct mtd_info *mtd = nand_to_mtd(chip);
> +
> +	for (i = 0; i < ARRAY_SIZE(broken_get_timings); i++) {
> +		if (!strcmp(broken_get_timings[i], chip->parameters.model)) {
> +			blockprotected = 1;
> +			break;
> +		}
> +	}
> +
> +	if (blockprotected && chip->parameters.supports_set_get_features) {
> +		bitmap_set(chip->parameters.set_feature_list,
> +			   ONFI_FEATURE_ADDR_MXIC_PROTECTION, 1);
> +		bitmap_set(chip->parameters.get_feature_list,
> +			   ONFI_FEATURE_ADDR_MXIC_PROTECTION, 1);
> +
> +		mtd->_lock = mxic_nand_lock;
> +		mtd->_unlock = mxic_nand_unlock;
> +	}
> +}
> +
>  const struct nand_manufacturer_ops macronix_nand_manuf_ops = {
>  	.init = macronix_nand_init,
> +	.post_init = macronix_nand_post_init,
>  };


Thanks,
Miquèl

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

  reply	other threads:[~2019-10-07  8:46 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-18  7:56 [PATCH RFC 1/3] mtd: rawnand: Add support manufacturer postponed initialization Mason Yang
2019-09-18  7:56 ` [PATCH RFC 2/3] mtd: rawnand: Add support Macronix Block Protection function Mason Yang
2019-10-07  8:45   ` Miquel Raynal [this message]
2019-10-07  9:24     ` Miquel Raynal
2019-10-08  2:33       ` masonccyang
2019-10-08 15:02         ` Miquel Raynal
2019-10-15  6:47           ` masonccyang
     [not found]           ` <OFB4F10613.467EB346-ON48258494.0020403E-48258494.002550A2@LocalDomain>
2019-10-21  7:23             ` masonccyang
2019-10-21  7:44               ` Boris Brezillon
2019-10-21  8:40                 ` masonccyang
2019-10-21  8:56                   ` Boris Brezillon
2019-10-21  9:07                     ` masonccyang
2019-09-18  7:56 ` [PATCH RFC 3/3] mtd: rawnand: Add support Macronix power down mode Mason Yang
2019-10-07  8:45   ` Miquel Raynal
2019-10-08  2:06     ` masonccyang
2019-10-08  7:28       ` Boris Brezillon
2019-10-15  2:33         ` masonccyang
2019-10-15  7:56           ` Miquel Raynal
2019-10-16  6:55             ` masonccyang
2019-10-25  3:11         ` 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=20191007104511.5aa7b8f2@xps13 \
    --to=miquel.raynal@bootlin.com \
    --cc=bbrezillon@kernel.org \
    --cc=computersforpeace@gmail.com \
    --cc=dwmw2@infradead.org \
    --cc=frieder.schrempf@kontron.de \
    --cc=gregkh@linuxfoundation.org \
    --cc=juliensu@mxic.com.tw \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mtd@lists.infradead.org \
    --cc=marcel.ziswiler@toradex.com \
    --cc=marek.vasut@gmail.com \
    --cc=masonccyang@mxic.com.tw \
    --cc=richard@nod.at \
    --cc=tglx@linutronix.de \
    --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).