All of lore.kernel.org
 help / color / mirror / Atom feed
From: Vignesh R <vigneshr@ti.com>
To: Boris Brezillon <boris.brezillon@bootlin.com>,
	Tudor Ambarus <tudor.ambarus@microchip.com>,
	Marek Vasut <marek.vasut@gmail.com>
Cc: Yogesh Narayan Gaur <yogeshnarayan.gaur@nxp.com>,
	Miquel Raynal <miquel.raynal@bootlin.com>,
	David Woodhouse <dwmw2@infradead.org>,
	Brian Norris <computersforpeace@gmail.com>,
	Richard Weinberger <richard@nod.at>,
	<linux-mtd@lists.infradead.org>
Subject: Re: [RFC PATCH 13/34] mtd: spi-nor: Add the concept of SPI NOR manufacturer driver
Date: Mon, 10 Dec 2018 13:50:03 +0530	[thread overview]
Message-ID: <e0db2bce-df36-9068-cc41-149e9c919b1e@ti.com> (raw)
In-Reply-To: <20181207092637.18687-14-boris.brezillon@bootlin.com>

Hi Boris,

On 07/12/18 2:56 PM, Boris Brezillon wrote:
> Declare a spi_nor_manufacturer struct and add basic building blocks to
> move manufacturer specific code outside of the core. We also rename
> spi-nor.c into spi-nor-core.c and adjust the Makefile to be able to
> create spi-nor.o by linking the core and manufacturer drivers together.
> 
> Signed-off-by: Boris Brezillon <boris.brezillon@bootlin.com>
> ---
>  drivers/mtd/spi-nor/core.c      | 82 +++++++++++++++++++++++++++------
>  drivers/mtd/spi-nor/internals.h | 14 ++++++
>  include/linux/mtd/spi-nor.h     |  8 ++++
>  3 files changed, 89 insertions(+), 15 deletions(-)
> 
> diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c
> index f8b7c8fbe960..8efd0490d2a0 100644
> --- a/drivers/mtd/spi-nor/core.c
> +++ b/drivers/mtd/spi-nor/core.c
> @@ -1722,6 +1722,23 @@ static const struct flash_info spi_nor_ids[] = {
>  	{ },
>  };
>  
> +static const struct spi_nor_manufacturer *manufacturers[0];
> +
> +static const struct flash_info *
> +spi_nor_search_part_by_id(const struct flash_info *parts, unsigned int nparts,
> +			  const u8 *id)
> +{
> +	unsigned int i;
> +
> +	for (i = 0; i < nparts; i++) {
> +		if (parts[i].id_len &&
> +		    !memcmp(parts[i].id, id, parts[i].id_len))
> +			return &parts[i];
> +	}
> +
> +	return NULL;
> +}
> +
>  static const struct flash_info *spi_nor_read_id(struct spi_nor *nor)
>  {
>  	int			tmp;
> @@ -1734,13 +1751,21 @@ static const struct flash_info *spi_nor_read_id(struct spi_nor *nor)
>  		return ERR_PTR(tmp);
>  	}
>  
> -	for (tmp = 0; tmp < ARRAY_SIZE(spi_nor_ids) - 1; tmp++) {
> -		info = &spi_nor_ids[tmp];
> -		if (info->id_len) {
> -			if (!memcmp(info->id, id, info->id_len))
> -				return &spi_nor_ids[tmp];
> +	for (tmp = 0; tmp < ARRAY_SIZE(manufacturers); tmp++) {
> +		info = spi_nor_search_part_by_id(manufacturers[tmp]->parts,
> +						 manufacturers[tmp]->nparts,
> +						 id);

This could probably be optimized a bit by comparing manufacturer ID and
then looking through parts list of that particular manufacturer only.
(with expection of winbond manufacturer ID, where will have to go
through spansion parts list as well)

Regards
Vignesh

> +		if (info) {
> +			nor->manufacturer = manufacturers[tmp];
> +			return info;
>  		}
>  	}
> +
> +	info = spi_nor_search_part_by_id(spi_nor_ids,
> +					 ARRAY_SIZE(spi_nor_ids) - 1, id);
> +	if (info)
> +		return info;
> +
>  	dev_err(nor->dev, "unrecognized JEDEC id bytes: %02x, %02x, %02x\n",
>  		id[0], id[1], id[2]);
>  	return ERR_PTR(-ENODEV);
> @@ -2334,9 +2359,22 @@ spi_nor_post_bfpt_fixups(struct spi_nor *nor,
>  			 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);
> +	int ret;
> +
> +	if (nor->manufacturer && nor->manufacturer->fixups &&
> +	    nor->manufacturer->fixups->post_bfpt) {
> +		ret = nor->manufacturer->fixups->post_bfpt(nor, bfpt_header,
> +							   bfpt, params);
> +		if (ret)
> +			return ret;
> +	}
> +
> +	if (nor->info->fixups && nor->info->fixups->post_bfpt) {
> +		ret = nor->info->fixups->post_bfpt(nor, bfpt_header, bfpt,
> +						   params);
> +		if (ret)
> +			return ret;
> +	}
>  
>  	return 0;
>  }
> @@ -3426,6 +3464,10 @@ static int
>  spi_nor_manufacturer_post_sfdp_fixups(struct spi_nor *nor,
>  				      struct spi_nor_flash_parameter *params)
>  {
> +	if (nor->manufacturer && nor->manufacturer->fixups &&
> +	    nor->manufacturer->fixups->post_sfdp)
> +		return nor->manufacturer->fixups->post_sfdp(nor, params);
> +
>  	switch (JEDEC_MFR(nor->info)) {
>  	case SNOR_MFR_ATMEL:
>  		atmel_post_sfdp_fixups(nor);
> @@ -3481,15 +3523,25 @@ static int spi_nor_post_sfdp_fixups(struct spi_nor *nor,
>  	return ret;
>  }
>  
> -static const struct flash_info *spi_nor_match_id(const char *name)
> +static const struct flash_info *spi_nor_match_id(struct spi_nor *nor,
> +						 const char *name)
>  {
> -	const struct flash_info *id = spi_nor_ids;
> +	unsigned int i, j;
>  
> -	while (id->name) {
> -		if (!strcmp(name, id->name))
> -			return id;
> -		id++;
> +	for (i = 0; i < ARRAY_SIZE(spi_nor_ids) - 1; i++) {
> +		if (!strcmp(name, spi_nor_ids[i].name))
> +			return &spi_nor_ids[i];
>  	}
> +
> +	for (i = 0; i < ARRAY_SIZE(manufacturers); i++) {
> +		for (j = 0; j < manufacturers[i]->nparts; j++) {
> +			if (!strcmp(name, manufacturers[i]->parts[j].name)) {
> +				nor->manufacturer = manufacturers[i];
> +				return &manufacturers[i]->parts[j];
> +			}
> +		}
> +	}
> +
>  	return NULL;
>  }
>  
> @@ -3514,7 +3566,7 @@ int spi_nor_scan(struct spi_nor *nor, const char *name,
>  	nor->write_proto = SNOR_PROTO_1_1_1;
>  
>  	if (name)
> -		info = spi_nor_match_id(name);
> +		info = spi_nor_match_id(nor, name);
>  	/* Try to auto-detect if chip name wasn't specified or not found */
>  	if (!info)
>  		info = spi_nor_read_id(nor);
> diff --git a/drivers/mtd/spi-nor/internals.h b/drivers/mtd/spi-nor/internals.h
> index cc06fed99f49..c442d0bfa21a 100644
> --- a/drivers/mtd/spi-nor/internals.h
> +++ b/drivers/mtd/spi-nor/internals.h
> @@ -318,4 +318,18 @@ struct flash_info {
>  		.addr_width = 3,					\
>  		.flags = SPI_NOR_NO_FR | SPI_S3AN,
>  
> +/**
> + * struct spi_nor_manufacturer - SPI NOR manufacturer object
> + * @name: manufacturer name
> + * @parts: array of parts supported by this manufacturer
> + * @nparts: number of entries in the parts array
> + * @fixups: hooks called at various points in time during spi_nor_scan()
> + */
> +struct spi_nor_manufacturer {
> +	const char *name;
> +	const struct flash_info *parts;
> +	unsigned int nparts;
> +	const struct spi_nor_fixups *fixups;
> +};
> +
>  #endif /* __LINUX_MTD_SPI_NOR_INTERNALS_H */
> diff --git a/include/linux/mtd/spi-nor.h b/include/linux/mtd/spi-nor.h
> index 8c64f1dcd35e..44ab116ce3d9 100644
> --- a/include/linux/mtd/spi-nor.h
> +++ b/include/linux/mtd/spi-nor.h
> @@ -332,12 +332,19 @@ struct spi_nor_erase_map {
>   */
>  struct flash_info;
>  
> +/**
> + * struct flash_info - Forward declaration of a structure used internally by
> + *		       the core and manufacturer drivers
> + */
> +struct spi_nor_manufacturer;
> +
>  /**
>   * struct spi_nor - Structure for defining a the SPI NOR layer
>   * @mtd:		point to a mtd_info structure
>   * @lock:		the lock for the read/write/erase/lock/unlock operations
>   * @dev:		point to a spi device, or a spi nor controller device.
>   * @info:		spi-nor part JDEC MFR id and other info
> + * @manufacturer:	spi-nor manufacturer
>   * @page_size:		the page size of the SPI NOR
>   * @addr_width:		number of address bytes
>   * @erase_opcode:	the opcode for erasing a sector
> @@ -376,6 +383,7 @@ struct spi_nor {
>  	struct mutex		lock;
>  	struct device		*dev;
>  	const struct flash_info	*info;
> +	const struct spi_nor_manufacturer *manufacturer;
>  	u32			page_size;
>  	u8			addr_width;
>  	u8			erase_opcode;
> 

-- 
Regards
Vignesh

  reply	other threads:[~2018-12-10  8:19 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-12-07  9:26 [RFC PATCH 00/34] mtd: spi-nor: Move manufacturer/SFDP code out of the core Boris Brezillon
2018-12-07  9:26 ` [RFC PATCH 01/34] mtd: spi-nor: Add a new hook to let part specific code tweak the config Boris Brezillon
2018-12-07 16:29   ` Sverdlin, Alexander (Nokia - DE/Ulm)
2018-12-10  9:06     ` Boris Brezillon
2018-12-07  9:26 ` [RFC PATCH 02/34] mtd: spi-nor: Add a post SFDP fixup hook for gd25q256 Boris Brezillon
2018-12-07  9:26 ` [RFC PATCH 03/34] mtd: spi-nor: Create a ->set_4byte() method Boris Brezillon
2018-12-07  9:26 ` [RFC PATCH 04/34] mtd: spi-nor: Add spansion_fixups() Boris Brezillon
2018-12-07  9:26 ` [RFC PATCH 05/34] mtd: spi-nor: Rework the SPI NOR lock/unlock logic Boris Brezillon
2018-12-07  9:26 ` [RFC PATCH 06/34] mtd: spi-nor: Rework the ->quad_enable() selection logic Boris Brezillon
2018-12-07  9:26 ` [RFC PATCH 07/34] mtd: spi-nor: Add a new flag to clear SW protection bits during init Boris Brezillon
2018-12-07  9:26 ` [RFC PATCH 08/34] mtd: spi-nor: Add a ->convert_addr() method Boris Brezillon
2018-12-07  9:26 ` [RFC PATCH 09/34] mtd: spi-nor: Add a flag to skip spi_nor_setup() Boris Brezillon
2018-12-10  8:30   ` Vignesh R
2018-12-10  8:37     ` Boris Brezillon
2018-12-07  9:26 ` [RFC PATCH 10/34] mtd: spi-nor: Add the SPI_NOR_XSR_RDY flag Boris Brezillon
2018-12-07  9:26 ` [RFC PATCH 11/34] mtd: spi-nor: Move S3AN fixups to the manufacturer fixups path Boris Brezillon
2018-12-07  9:26 ` [RFC PATCH 12/34] mtd: spi-nor: Prepare things for core / manufacturer code split Boris Brezillon
2018-12-07  9:26 ` [RFC PATCH 13/34] mtd: spi-nor: Add the concept of SPI NOR manufacturer driver Boris Brezillon
2018-12-10  8:20   ` Vignesh R [this message]
2018-12-10  8:35     ` Boris Brezillon
2018-12-10 11:28       ` Vignesh R
2018-12-07  9:26 ` [RFC PATCH 14/34] mtd: spi-nor: Stop prefixing generic functions with a manufacturer name Boris Brezillon
2018-12-07  9:26 ` [RFC PATCH 15/34] mtd: spi-nor: Expose some functions to manufacturer drivers Boris Brezillon
2018-12-07  9:26 ` [RFC PATCH 16/34] mtd: spi-nor: Move Atmel bits out of core.c Boris Brezillon
2018-12-07  9:26 ` [RFC PATCH 17/34] mtd: spi-nor: Move Eon " Boris Brezillon
2018-12-07  9:26 ` [RFC PATCH 18/34] mtd: spi-nor: Move ESMT " Boris Brezillon
2018-12-07  9:26 ` [RFC PATCH 19/34] mtd: spi-nor: Move Everspin " Boris Brezillon
2018-12-07  9:26 ` [RFC PATCH 20/34] mtd: spi-nor: Move Fujitsu bits out of spi-nor-core.c Boris Brezillon
2018-12-07  9:26 ` [RFC PATCH 21/34] mtd: spi-nor: Move GigaDevice bits out of core.c Boris Brezillon
2018-12-07  9:26 ` [RFC PATCH 22/34] mtd: spi-nor: Move Intel " Boris Brezillon
2018-12-07  9:26 ` [RFC PATCH 23/34] mtd: spi-nor: Move ISSI " Boris Brezillon
2018-12-07  9:26 ` [RFC PATCH 24/34] mtd: spi-nor: Move Macronix " Boris Brezillon
2018-12-07  9:26 ` [RFC PATCH 25/34] mtd: spi-nor: Move Micron/ST " Boris Brezillon
2018-12-07  9:26 ` [RFC PATCH 26/34] mtd: spi-nor: Move Spansion " Boris Brezillon
2018-12-07  9:26 ` [RFC PATCH 27/34] mtd: spi-nor: Move SST " Boris Brezillon
2018-12-07  9:26 ` [RFC PATCH 28/34] mtd: spi-nor: Move Winbond " Boris Brezillon
2018-12-07  9:26 ` [RFC PATCH 29/34] mtd: spi-nor: Move Catalyst " Boris Brezillon
2018-12-07  9:26 ` [RFC PATCH 30/34] mtd: spi-nor: Move Xilinx " Boris Brezillon
2018-12-07  9:26 ` [RFC PATCH 31/34] mtd: spi-nor: Move XMC " Boris Brezillon
2018-12-07  9:26 ` [RFC PATCH 32/34] mtd: spi-nor: Get rid of the now empty spi_nor_ids[] table Boris Brezillon
2018-12-07  9:26 ` [RFC PATCH 33/34] mtd: spi-nor: Move SFDP parsing code out of core.c Boris Brezillon
2018-12-07  9:26 ` [RFC PATCH 34/34] mtd: spi-nor: Add sfdp fixups hooks Boris Brezillon
2018-12-07 16:29   ` Sverdlin, Alexander (Nokia - DE/Ulm)
2018-12-10  9:12     ` Boris Brezillon

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=e0db2bce-df36-9068-cc41-149e9c919b1e@ti.com \
    --to=vigneshr@ti.com \
    --cc=boris.brezillon@bootlin.com \
    --cc=computersforpeace@gmail.com \
    --cc=dwmw2@infradead.org \
    --cc=linux-mtd@lists.infradead.org \
    --cc=marek.vasut@gmail.com \
    --cc=miquel.raynal@bootlin.com \
    --cc=richard@nod.at \
    --cc=tudor.ambarus@microchip.com \
    --cc=yogeshnarayan.gaur@nxp.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.