[U-Boot] [U-BOOT PATCH 1/3] spi: nor: add spi-nor-fixup handlers for nor devices

Bin Meng bmeng.cn at gmail.com
Mon Aug 26 12:51:30 UTC 2019


On Wed, Aug 14, 2019 at 1:36 AM Sagar Shrikant Kadam
<sagar.kadam at sifive.com> wrote:
>
> Add support for spi_nor_fixups similar to that done in linux.
> Flash vendor specific fixups can be registered in spi_nor_ids.
> and will be called after BFPT parsing to fix any wrong parameter
> read from SFDP.
>
> Signed-off-by: Sagar Shrikant Kadam <sagar.kadam at sifive.com>
> ---
>  drivers/mtd/spi/sf_internal.h  |  5 +++++
>  drivers/mtd/spi/spi-nor-core.c | 33 +++++++++++++++++++++++++++++++--
>  2 files changed, 36 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/mtd/spi/sf_internal.h b/drivers/mtd/spi/sf_internal.h
> index a6bf734..c5e68d8 100644
> --- a/drivers/mtd/spi/sf_internal.h
> +++ b/drivers/mtd/spi/sf_internal.h
> @@ -65,6 +65,11 @@ struct flash_info {
>  #define NO_CHIP_ERASE          BIT(12) /* Chip does not support chip erase */
>  #define SPI_NOR_SKIP_SFDP      BIT(13) /* Skip parsing of SFDP tables */
>  #define USE_CLSR               BIT(14) /* use CLSR command */
> +
> +#ifdef CONFIG_SPI_FLASH_SFDP_SUPPORT
> +       /* Part specific fixup hooks */
> +       const struct spi_nor_fixups     *fixups;
> +#endif
>  };
>
>  extern const struct flash_info spi_nor_ids[];
> diff --git a/drivers/mtd/spi/spi-nor-core.c b/drivers/mtd/spi/spi-nor-core.c
> index 1acff74..4306d19 100644
> --- a/drivers/mtd/spi/spi-nor-core.c
> +++ b/drivers/mtd/spi/spi-nor-core.c
> @@ -1623,6 +1623,33 @@ static const struct sfdp_bfpt_erase sfdp_bfpt_erases[] = {
>  static int spi_nor_hwcaps_read2cmd(u32 hwcaps);
>
>  /**
> + * struct spi_nor_fixups - SPI NOR fixup hooks
> + * @post_bfpt: called after the BFPT table has been parsed
> + *
> + * Those hooks can be used to tweak the SPI NOR configuration when the SFDP
> + * table is broken or not available.
> + */
> +struct spi_nor_fixups {
> +       int (*post_bfpt)(struct spi_nor *nor,
> +                        const struct sfdp_parameter_header *bfpt_header,
> +                        const struct sfdp_bfpt *bfpt,
> +                        struct spi_nor_flash_parameter *params);
> +};
> +
> +static int

nits: this should be in the same line as the function name

> +spi_nor_post_bfpt_fixups(struct spi_nor *nor,
> +                        const struct sfdp_parameter_header *bfpt_header,
> +                        const struct sfdp_bfpt *bfpt,
> +                        struct spi_nor_flash_parameter *params)
> +{
> +       if (nor->info->fixups && nor->info->fixups->post_bfpt)
> +               return nor->info->fixups->post_bfpt(nor, bfpt_header, bfpt,
> +                               params);
> +
> +       return 0;
> +}
> +
> +/**
>   * spi_nor_parse_bfpt() - read and parse the Basic Flash Parameter Table.
>   * @nor:               pointer to a 'struct spi_nor'
>   * @bfpt_header:       pointer to the 'struct sfdp_parameter_header' describing
> @@ -1760,7 +1787,8 @@ static int spi_nor_parse_bfpt(struct spi_nor *nor,
>
>         /* Stop here if not JESD216 rev A or later. */
>         if (bfpt_header->length < BFPT_DWORD_MAX)
> -               return 0;
> +               return spi_nor_post_bfpt_fixups(nor, bfpt_header, &bfpt,
> +                               params);
>
>         /* Page size: this field specifies 'N' so the page size = 2^N bytes. */
>         params->page_size = bfpt.dwords[BFPT_DWORD(11)];
> @@ -1793,7 +1821,8 @@ static int spi_nor_parse_bfpt(struct spi_nor *nor,
>                 return -EINVAL;
>         }
>
> -       return 0;
> +       return spi_nor_post_bfpt_fixups(nor, bfpt_header, &bfpt,
> +                       params);
>  }
>

Regards,
Bin


More information about the U-Boot mailing list