From: Miquel Raynal <miquel.raynal@bootlin.com>
To: William Zhang <william.zhang@broadcom.com>
Cc: Linux MTD List <linux-mtd@lists.infradead.org>,
Linux ARM List <linux-arm-kernel@lists.infradead.org>,
Broadcom Kernel List <bcm-kernel-feedback-list@broadcom.com>,
f.fainelli@gmail.com, kursad.oney@broadcom.com,
joel.peshkin@broadcom.com, anand.gore@broadcom.com,
dregan@mail.com, kamal.dasu@broadcom.com,
tomer.yacoby@broadcom.com, dan.beygelman@broadcom.com,
David Regan <dregan@broadcom.com>,
linux-kernel@vger.kernel.org,
Vignesh Raghavendra <vigneshr@ti.com>,
Brian Norris <computersforpeace@gmail.com>,
Richard Weinberger <richard@nod.at>
Subject: Re: [PATCH v6 12/13] mtd: rawnand: brcmnand: Add support for getting ecc setting from strap
Date: Fri, 23 Feb 2024 10:18:52 +0100 [thread overview]
Message-ID: <20240223101852.005da3ad@xps-13> (raw)
In-Reply-To: <20240223034758.13753-13-william.zhang@broadcom.com>
Hi William,
william.zhang@broadcom.com wrote on Thu, 22 Feb 2024 19:47:57 -0800:
> BCMBCA broadband SoC based board design does not specify ecc setting in
> dts but rather use the SoC NAND strap info to obtain the ecc strength
> and spare area size setting. Add brcm,nand-ecc-use-strap dts propety for
> this purpose and update driver to support this option. However these two
> options can not be used at the same time.
>
> Signed-off-by: William Zhang <william.zhang@broadcom.com>
> Reviewed-by: David Regan <dregan@broadcom.com>
>
FYI I did not receive patches 7, 8, 9, which makes the series numbering
very odd.
> ---
>
> Changes in v6:
> - Combine the ecc step size and ecc strength into one get function
> - Treat it as error condition if both brcm,nand-ecc-use-strap and nand
> ecc dts properties are set
> - Add intermediate steps to get the sector size bitfield
>
> Changes in v5: None
> Changes in v4:
> - Update the comments for ecc setting selection
>
> Changes in v3: None
> Changes in v2:
> - Minor cosmetic fixes
>
> drivers/mtd/nand/raw/brcmnand/brcmnand.c | 83 ++++++++++++++++++++++--
> 1 file changed, 77 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/mtd/nand/raw/brcmnand/brcmnand.c b/drivers/mtd/nand/raw/brcmnand/brcmnand.c
> index ef7d340475be..e8ffc283b365 100644
> --- a/drivers/mtd/nand/raw/brcmnand/brcmnand.c
> +++ b/drivers/mtd/nand/raw/brcmnand/brcmnand.c
> @@ -1038,6 +1038,22 @@ static inline int brcmnand_sector_1k_shift(struct brcmnand_controller *ctrl)
> return -1;
> }
>
> +static int brcmnand_get_sector_size_1k(struct brcmnand_host *host)
> +{
> + struct brcmnand_controller *ctrl = host->ctrl;
> + int sector_size_bit = brcmnand_sector_1k_shift(ctrl);
> + u16 acc_control_offs = brcmnand_cs_offset(ctrl, host->cs,
> + BRCMNAND_CS_ACC_CONTROL);
> + u32 acc_control;
> +
> + if (sector_size_bit < 0)
> + return 0;
> +
> + acc_control = nand_readreg(ctrl, acc_control_offs);
> +
> + return (acc_control & BIT(sector_size_bit)) >> sector_size_bit;
FIELD_PREP, FIELD_GET, *please*.
> +}
> +
> static void brcmnand_set_sector_size_1k(struct brcmnand_host *host, int val)
> {
> struct brcmnand_controller *ctrl = host->ctrl;
> @@ -1055,6 +1071,43 @@ static void brcmnand_set_sector_size_1k(struct brcmnand_host *host, int val)
> nand_writereg(ctrl, acc_control_offs, tmp);
> }
>
> +static int brcmnand_get_spare_size(struct brcmnand_host *host)
> +{
> + struct brcmnand_controller *ctrl = host->ctrl;
> + u16 acc_control_offs = brcmnand_cs_offset(ctrl, host->cs,
> + BRCMNAND_CS_ACC_CONTROL);
> + u32 acc = nand_readreg(ctrl, acc_control_offs);
> +
> + return (acc & brcmnand_spare_area_mask(ctrl));
> +}
> +
> +static void brcmnand_get_ecc_settings(struct brcmnand_host *host, struct nand_chip *chip)
> +{
> + struct brcmnand_controller *ctrl = host->ctrl;
> + u16 acc_control_offs = brcmnand_cs_offset(ctrl, host->cs,
> + BRCMNAND_CS_ACC_CONTROL);
> + int sector_size_1k = brcmnand_get_sector_size_1k(host);
> + int spare_area_size, ecc_level;
> + u32 acc;
> +
> + spare_area_size = brcmnand_get_spare_size(host);
> + acc = nand_readreg(ctrl, acc_control_offs);
> + ecc_level = (acc & brcmnand_ecc_level_mask(ctrl)) >> ctrl->ecc_level_shift;
ditto
> + if (sector_size_1k)
> + chip->ecc.strength = ecc_level * 2;
> + else if (spare_area_size == 16 && ecc_level == 15)
> + chip->ecc.strength = 1; /* hamming */
> + else
> + chip->ecc.strength = ecc_level;
> +
> + if (chip->ecc.size == 0) {
> + if (sector_size_1k < 0)
Should be <= 0 I guess
> + chip->ecc.size = 512;
> + else
> + chip->ecc.size = 512 << sector_size_1k;
What is this? Are you expecting sector_size_1k to be 0 or 1
and thus multiply 512 by two?
Please just use:
chip->ecc.size = SZ_1K;
> + }
> +}
> +
> /***********************************************************************
> * CS_NAND_SELECT
> ***********************************************************************/
> @@ -2625,19 +2678,37 @@ static int brcmnand_setup_dev(struct brcmnand_host *host)
> nanddev_get_memorg(&chip->base);
> struct brcmnand_controller *ctrl = host->ctrl;
> struct brcmnand_cfg *cfg = &host->hwcfg;
> - char msg[128];
> + struct device_node *np = nand_get_flash_node(chip);
> u32 offs, tmp, oob_sector;
> + bool use_strap = false;
> + char msg[128];
> int ret;
>
> memset(cfg, 0, sizeof(*cfg));
> + use_strap = of_property_read_bool(np, "brcm,nand-ecc-use-strap");
>
> - ret = of_property_read_u32(nand_get_flash_node(chip),
> - "brcm,nand-oob-sector-size",
> + /*
> + * Either nand-ecc-xxx or brcm,nand-ecc-use-strap can be set. Error out
> + * if both exist.
> + */
Thanks for the comment but I think the error string is clear enough.
> + if (chip->ecc.strength && use_strap) {
> + dev_err(ctrl->dev,
> + "nand ecc and strap ecc settings can't be set at the same time\n");
Can we change to
"ECC strap and DT ECC configuration properties are mutually exclusive"
> + return -EINVAL;
> + }
> +
> + if (use_strap)
> + brcmnand_get_ecc_settings(host, chip);
> +
> + ret = of_property_read_u32(np, "brcm,nand-oob-sector-size",
> &oob_sector);
> if (ret) {
> - /* Use detected size */
> - cfg->spare_area_size = mtd->oobsize /
> - (mtd->writesize >> FC_SHIFT);
> + if (use_strap)
> + cfg->spare_area_size = brcmnand_get_spare_size(host);
> + else
> + /* Use detected size */
> + cfg->spare_area_size = mtd->oobsize /
> + (mtd->writesize >> FC_SHIFT);
> } else {
> cfg->spare_area_size = oob_sector;
> }
The rest of the series looks good to me.
Thanks,
Miquèl
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
next prev parent reply other threads:[~2024-02-23 9:20 UTC|newest]
Thread overview: 40+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-23 3:47 [PATCH v6 00/13] mtd: rawnand: brcmnand: driver and doc updates William Zhang
2024-02-23 3:47 ` [PATCH v6 01/13] mtd: rawnand: brcmnand: exec_op helper functions return type fixes William Zhang
2024-02-23 4:20 ` Florian Fainelli
2024-02-26 10:44 ` Miquel Raynal
2024-02-23 3:47 ` [PATCH v6 02/13] mtd: rawnand: brcmnand: fix style issues William Zhang
2024-02-26 10:44 ` Miquel Raynal
2024-02-23 3:47 ` [PATCH v6 03/13] mtd: rawnand: brcmnand: update log level messages William Zhang
2024-02-26 10:44 ` Miquel Raynal
2024-02-23 3:47 ` [PATCH v6 04/13] dt-bindings: mtd: brcmnand: Updates for bcmbca SoCs William Zhang
2024-02-26 10:44 ` Miquel Raynal
2024-02-23 3:47 ` [PATCH v6 05/13] dt-bindings: mtd: brcmnand: Add WP pin connection property William Zhang
2024-02-26 10:44 ` Miquel Raynal
2024-02-23 3:47 ` [PATCH v6 06/13] dt-bindings: mtd: brcmnand: Add ecc strap property William Zhang
2024-02-23 18:47 ` Conor Dooley
2024-02-26 10:44 ` Miquel Raynal
2024-02-23 3:47 ` [PATCH v6 07/13] ARM: dts: broadcom: bcmbca: Add NAND controller node William Zhang
2024-02-26 10:44 ` Miquel Raynal
2024-02-23 3:47 ` [PATCH v6 08/13] arm64: " William Zhang
2024-02-26 10:44 ` Miquel Raynal
2024-02-23 3:47 ` [PATCH v6 09/13] arm64: dts: broadcom: bcmbca: Update router boards William Zhang
2024-02-26 10:44 ` Miquel Raynal
2024-02-23 3:47 ` [PATCH v6 10/13] mtd: rawnand: brcmnand: Rename bcm63138 nand driver William Zhang
2024-02-26 10:43 ` Miquel Raynal
2024-02-23 3:47 ` [PATCH v6 11/13] mtd: rawnand: brcmnand: Add BCMBCA read data bus interface William Zhang
2024-02-26 10:43 ` Miquel Raynal
2024-02-23 3:47 ` [PATCH v6 12/13] mtd: rawnand: brcmnand: Add support for getting ecc setting from strap William Zhang
2024-02-23 9:18 ` Miquel Raynal [this message]
2024-02-23 17:25 ` William Zhang
2024-02-26 8:36 ` Miquel Raynal
2024-02-26 20:05 ` William Zhang
2024-02-29 10:31 ` Miquel Raynal
2024-02-29 23:34 ` William Zhang
2024-02-23 3:47 ` [PATCH v6 13/13] mtd: rawnand: brcmnand: Support write protection setting from dts William Zhang
2024-02-26 10:43 ` Miquel Raynal
2024-02-26 17:36 ` [PATCH v6 00/13] mtd: rawnand: brcmnand: driver and doc updates Florian Fainelli
2024-02-29 9:11 ` Miquel Raynal
2024-02-29 17:32 ` Florian Fainelli
2024-03-14 22:04 ` Miquel Raynal
2024-03-14 23:02 ` Florian Fainelli
2024-03-14 23:03 ` Miquel Raynal
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=20240223101852.005da3ad@xps-13 \
--to=miquel.raynal@bootlin.com \
--cc=anand.gore@broadcom.com \
--cc=bcm-kernel-feedback-list@broadcom.com \
--cc=computersforpeace@gmail.com \
--cc=dan.beygelman@broadcom.com \
--cc=dregan@broadcom.com \
--cc=dregan@mail.com \
--cc=f.fainelli@gmail.com \
--cc=joel.peshkin@broadcom.com \
--cc=kamal.dasu@broadcom.com \
--cc=kursad.oney@broadcom.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mtd@lists.infradead.org \
--cc=richard@nod.at \
--cc=tomer.yacoby@broadcom.com \
--cc=vigneshr@ti.com \
--cc=william.zhang@broadcom.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).