[PATCH v2 2/3] mtd: rawnand: meson: refactor use of 'meson_nfc_cmd_access()'

Michael Nazzareno Trimarchi michael at amarulasolutions.com
Mon Aug 26 08:32:04 CEST 2024


Hi

On Mon, Aug 26, 2024 at 8:17 AM Arseniy Krasnov
<avkrasnov at salutedevices.com> wrote:
>
> Move call 'meson_nfc_cmd_seed()' and check for 'NAND_NEED_SCRAMBLING'
> to 'meson_nfc_cmd_access()', thus removing code duplication.
>
> Signed-off-by: Arseniy Krasnov <avkrasnov at salutedevices.com>
> ---
>  drivers/mtd/nand/raw/meson_nand.c | 30 ++++++++++++------------------
>  1 file changed, 12 insertions(+), 18 deletions(-)
>
> diff --git a/drivers/mtd/nand/raw/meson_nand.c b/drivers/mtd/nand/raw/meson_nand.c
> index 5d411c4594..19f005202b 100644
> --- a/drivers/mtd/nand/raw/meson_nand.c
> +++ b/drivers/mtd/nand/raw/meson_nand.c
> @@ -229,14 +229,19 @@ static void meson_nfc_cmd_seed(const struct meson_nfc *nfc, u32 seed)
>                nfc->reg_base + NFC_REG_CMD);
>  }
>
> -static void meson_nfc_cmd_access(struct nand_chip *nand, bool raw, bool dir,
> -                                int scrambler)
> +static void meson_nfc_cmd_access(struct nand_chip *nand, bool raw, bool dir, int page)
>  {
>         struct mtd_info *mtd = nand_to_mtd(nand);
>         const struct meson_nfc *nfc = nand_get_controller_data(mtd_to_nand(mtd));
>         const struct meson_nfc_nand_chip *meson_chip = to_meson_nand(nand);
>         u32 bch = meson_chip->bch_mode, cmd;
>         int len = mtd->writesize, pagesize, pages;
> +       int scrambler;
> +

unsigned int

> +       if (nand->options & NAND_NEED_SCRAMBLING)
> +               scrambler = NFC_CMD_SCRAMBLER_ENABLE;
> +       else
> +               scrambler = NFC_CMD_SCRAMBLER_DISABLE;
>
>         pagesize = nand->ecc.size;
>
> @@ -252,6 +257,9 @@ static void meson_nfc_cmd_access(struct nand_chip *nand, bool raw, bool dir,
>         cmd = CMDRWGEN(DMA_DIR(dir), scrambler, bch,
>                        NFC_CMD_SHORTMODE_DISABLE, pagesize, pages);
>
> +       if (scrambler == NFC_CMD_SCRAMBLER_ENABLE)
> +               meson_nfc_cmd_seed(nfc, page);
> +
>         writel(cmd, nfc->reg_base + NFC_REG_CMD);
>  }
>
> @@ -566,14 +574,7 @@ static int meson_nfc_write_page_sub(struct nand_chip *nand,
>                 return ret;
>         }
>
> -       if (nand->options & NAND_NEED_SCRAMBLING) {
> -               meson_nfc_cmd_seed(nfc, page);
> -               meson_nfc_cmd_access(nand, raw, DIRWRITE,
> -                                    NFC_CMD_SCRAMBLER_ENABLE);
> -       } else {
> -               meson_nfc_cmd_access(nand, raw, DIRWRITE,
> -                                    NFC_CMD_SCRAMBLER_DISABLE);
> -       }
> +       meson_nfc_cmd_access(nand, raw, DIRWRITE, page);
>
>         cmd = nfc->param.chip_select | NFC_CMD_CLE | NAND_CMD_PAGEPROG;
>         writel(cmd, nfc->reg_base + NFC_REG_CMD);
> @@ -644,14 +645,7 @@ static int meson_nfc_read_page_sub(struct nand_chip *nand,
>         if (ret)
>                 return ret;
>
> -       if (nand->options & NAND_NEED_SCRAMBLING) {
> -               meson_nfc_cmd_seed(nfc, page);
> -               meson_nfc_cmd_access(nand, raw, DIRREAD,
> -                                    NFC_CMD_SCRAMBLER_ENABLE);
> -       } else {
> -               meson_nfc_cmd_access(nand, raw, DIRREAD,
> -                                    NFC_CMD_SCRAMBLER_DISABLE);
> -       }
> +       meson_nfc_cmd_access(nand, raw, DIRREAD, page);
>
>         meson_nfc_wait_dma_finish(nfc);
>         meson_nfc_check_ecc_pages_valid(nfc, nand, raw);
> --
> 2.30.1
>

Please change to unsigned int because I think match options type

With this

Reviewed-by: Michael Trimarchi <michael at amarulasolutions.com>


-- 
Michael Nazzareno Trimarchi
Co-Founder & Chief Executive Officer
M. +39 347 913 2170
michael at amarulasolutions.com
__________________________________

Amarula Solutions BV
Joop Geesinkweg 125, 1114 AB, Amsterdam, NL
T. +31 (0)85 111 9172
info at amarulasolutions.com
www.amarulasolutions.com


More information about the U-Boot mailing list