[PATCH 1/8] mtd: spi-nor: eliminate duplicate spi_nor_wait_till_{, fsr}_ready() code

Huang Shijie shijie8 at gmail.com
Fri Aug 8 23:25:45 PDT 2014


On Wed, Aug 06, 2014 at 06:16:55PM -0700, Brian Norris wrote:
> These functions were near-carbon-copies due to a small per-flash quirk.
> Let's add a new spi_nor::flags bitfield to support these types of
> quirks.
> 
> Signed-off-by: Brian Norris <computersforpeace at gmail.com>
> Cc: Graham Moore <grmoore at altera.com>
> Cc: Huang Shijie <b32955 at freescale.com>
> Signed-off-by: Brian Norris <computersforpeace at gmail.com>
> ---
>  drivers/mtd/spi-nor/spi-nor.c | 66 ++++++++++++++++++++++---------------------
>  include/linux/mtd/spi-nor.h   |  6 ++++
>  2 files changed, 40 insertions(+), 32 deletions(-)
> 
> diff --git a/drivers/mtd/spi-nor/spi-nor.c b/drivers/mtd/spi-nor/spi-nor.c
> index b5ad6bebf5e7..5825b8a12cee 100644
> --- a/drivers/mtd/spi-nor/spi-nor.c
> +++ b/drivers/mtd/spi-nor/spi-nor.c
> @@ -163,48 +163,51 @@ static inline int set_4byte(struct spi_nor *nor, u32 jedec_id, int enable)
>  		return nor->write_reg(nor, SPINOR_OP_BRWR, nor->cmd_buf, 1, 0);
>  	}
>  }
> -
> -static int spi_nor_wait_till_ready(struct spi_nor *nor)
> +static inline int spi_nor_sr_ready(struct spi_nor *nor)
>  {
> -	unsigned long deadline;
> -	int sr;
> -
> -	deadline = jiffies + MAX_READY_WAIT_JIFFIES;
> -
> -	do {
> -		cond_resched();
> +	int sr = read_sr(nor);
> +	if (sr < 0)
> +		return sr;
> +	else
> +		return !(sr & SR_WIP);
> +}
>  
> -		sr = read_sr(nor);
> -		if (sr < 0)
> -			break;
> -		else if (!(sr & SR_WIP))
> -			return 0;
> -	} while (!time_after_eq(jiffies, deadline));
> +static inline int spi_nor_fsr_ready(struct spi_nor *nor)
> +{
> +	int fsr = read_fsr(nor);
> +	if (fsr < 0)
> +		return fsr;
> +	else
> +		return fsr & FSR_READY;
> +}
>  
> -	return -ETIMEDOUT;
> +static int spi_nor_ready(struct spi_nor *nor)
> +{
> +	int sr, fsr;
> +	sr = spi_nor_sr_ready(nor);
> +	if (sr < 0)
> +		return sr;
> +	fsr = nor->flags & SNOR_F_USE_FSR ? spi_nor_fsr_ready(nor) : 1;
> +	if (fsr < 0)
> +		return sr;
return "fsr" here.

Beside this, i am ok with this patch.	
	
thanks
Huang Shijie



More information about the linux-mtd mailing list