[PATCH 09/15] mtd: spi-nor-core: Introduce flash-specific fixup hooks

Pratyush Yadav p.yadav at ti.com
Thu Mar 12 08:29:41 CET 2020


On 12/03/20 12:04PM, Vignesh Raghavendra wrote:
> 
> 
> On 26/02/20 6:25 pm, Pratyush Yadav wrote:
> > diff --git a/drivers/mtd/spi/spi-nor-core.c b/drivers/mtd/spi/spi-nor-core.c
> > index 1ed4f0907b..94e99eb99f 100644
> > --- a/drivers/mtd/spi/spi-nor-core.c
> > +++ b/drivers/mtd/spi/spi-nor-core.c
> > @@ -148,6 +148,32 @@ struct sfdp_header {
> >  struct sfdp_bfpt {
> >  	u32	dwords[BFPT_DWORD_MAX];
> >  };
> > +
> > +/**
> > + * struct spi_nor_fixups - SPI NOR fixup hooks
> > + * @default_init: called after default flash parameters init. Used to tweak
> > + *                flash parameters when information provided by the flash_info
> > + *                table is incomplete or wrong.
> > + * @post_bfpt: called after the BFPT table has been parsed
> > + * @post_sfdp: called after SFDP has been parsed (is also called for SPI NORs
> > + *             that do not support RDSFDP). Typically used to tweak various
> > + *             parameters that could not be extracted by other means (i.e.
> > + *             when information provided by the SFDP/flash_info tables are
> > + *             incomplete or wrong).
> > + *
> > + * Those hooks can be used to tweak the SPI NOR configuration when the SFDP
> > + * table is broken or not available.
> > + */
> > +struct spi_nor_fixups {
> > +	void (*default_init)(struct spi_nor *nor);
> > +	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);
> > +	void (*post_sfdp)(struct spi_nor *nor,
> > +			  struct spi_nor_flash_parameter *params);
> > +};
> > +
> >  #endif /* SPI_FLASH_SFDP_SUPPORT */
> >  
> >  static int spi_nor_read_write_reg(struct spi_nor *nor, struct spi_mem_op
> > @@ -1743,6 +1769,19 @@ static const struct sfdp_bfpt_erase sfdp_bfpt_erases[] = {
> >  
> >  static int spi_nor_hwcaps_read2cmd(u32 hwcaps);
> >  
> > +static int
> > +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'
> > @@ -1914,7 +1953,7 @@ 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);
> >  }
> >  
> >  /**
> > @@ -2074,6 +2113,29 @@ static int spi_nor_parse_sfdp(struct spi_nor *nor,
> >  }
> >  #endif /* SPI_FLASH_SFDP_SUPPORT */
> >  
> > +/**
> > + * spi_nor_post_sfdp_fixups() - Updates the flash's parameters and settings
> > + * after SFDP has been parsed (is also called for SPI NORs that do not
> > + * support RDSFDP).
> > + * @nor:	pointer to a 'struct spi_nor'
> > + *
> > + * Typically used to tweak various parameters that could not be extracted by
> > + * other means (i.e. when information provided by the SFDP/flash_info tables
> > + * are incomplete or wrong).
> > + */
> > +static void spi_nor_post_sfdp_fixups(struct spi_nor *nor,
> > +				     struct spi_nor_flash_parameter *params)
> > +{
> > +	if (nor->info->fixups && nor->info->fixups->post_sfdp)
> > +		nor->info->fixups->post_sfdp(nor, params);
> > +}
> > +
> 
> This would cause build failure as spi_nor_fixups is only available when 
> SFDP support is enabled:
> 
> drivers/mtd/spi/spi-nor-core.c: In function ‘spi_nor_post_sfdp_fixups’:
> drivers/mtd/spi/spi-nor-core.c:2280:44: error: dereferencing pointer to incomplete type ‘const struct spi_nor_fixups’
>  2280 |  if (nor->info->fixups && nor->info->fixups->post_sfdp)
> 
> May be move all definitions of out the #ifdef

Thanks for catching this. Will fix.

-- 
Regards,
Pratyush Yadav
Texas Instruments India


More information about the U-Boot mailing list