All of lore.kernel.org
 help / color / mirror / Atom feed
From: Boris Brezillon <boris.brezillon@collabora.com>
To: Chuanhong Guo <gch981213@gmail.com>
Cc: linux-mtd@lists.infradead.org,
	Boris Brezillon <bbrezillon@kernel.org>,
	Miquel Raynal <miquel.raynal@bootlin.com>,
	Richard Weinberger <richard@nod.at>,
	Vignesh Raghavendra <vigneshr@ti.com>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] mtd: nand: spi: rework detect procedure for different read id op
Date: Fri, 10 Jan 2020 07:58:59 +0100	[thread overview]
Message-ID: <20200110075859.3edfae3a@collabora.com> (raw)
In-Reply-To: <20200110025218.1257809-1-gch981213@gmail.com>

On Fri, 10 Jan 2020 10:51:14 +0800
Chuanhong Guo <gch981213@gmail.com> wrote:


> +static int spinand_manufacturer_detect(struct spinand_device *spinand)
> +{
> +	u8 *id = spinand->id.data;
> +	int ret;
> +
> +	ret = spinand_read_id_op(spinand, 0, 0, id);
> +	if (ret)
> +		return ret;
> +	ret = spinand_manufacturer_match(spinand, SPINAND_READID_METHOD_OPCODE);
> +	if (!ret)
> +		return 0;
> +
> +	ret = spinand_read_id_op(spinand, 1, 0, id);
> +	if (ret)
> +		return ret;
> +	ret = spinand_manufacturer_match(spinand,
> +					 SPINAND_READID_METHOD_OPCODE_ADDR);
> +	if (!ret)
> +		return 0;
> +
> +	ret = spinand_read_id_op(spinand, 0, 1, id);

Hm, we should probably do only one of each read_id and iterate over all
manufacturers/chips each time instead of doing 3 read_ids per
manufacturer.

> +	if (ret)
> +		return ret;
> +	ret = spinand_manufacturer_match(spinand,
> +					 SPINAND_READID_METHOD_OPCODE_DUMMY);
> +
> +	return ret;
> +}
> +

[...]

> +/**
> + * struct spinand_devid - SPI NAND device id structure
> + * @id: device id of current chip
> + * @len: number of bytes in device id
> + * @method: method to read chip id
> + *	    There are 3 possible variants:
> + *	    SPINAND_READID_METHOD_OPCODE: chip id is returned immediately
> + *	    after read_id opcode.
> + *	    SPINAND_READID_METHOD_OPCODE_ADDR: chip id is returned after
> + *	    read_id opcode + 1-byte address.
> + *	    SPINAND_READID_METHOD_OPCODE_DUMMY: chip id is returned after
> + *	    read_id opcode + 1 dummy byte.
> + */
> +struct spinand_devid {
> +	u16 id;

Can we make that field an array of u8?

	const u8 *id;

> +	u8 len;
> +	enum spinand_readid_method method;
> +};
> +
>  /**
>   * struct manufacurer_ops - SPI NAND manufacturer specific operations
> - * @detect: detect a SPI NAND device. Every time a SPI NAND device is probed
> - *	    the core calls the struct_manufacurer_ops->detect() hook of each
> - *	    registered manufacturer until one of them return 1. Note that
> - *	    the first thing to check in this hook is that the manufacturer ID
> - *	    in struct_spinand_device->id matches the manufacturer whose
> - *	    ->detect() hook has been called. Should return 1 if there's a
> - *	    match, 0 if the manufacturer ID does not match and a negative
> - *	    error code otherwise. When true is returned, the core assumes
> - *	    that properties of the NAND chip (spinand->base.memorg and
> - *	    spinand->base.eccreq) have been filled
>   * @init: initialize a SPI NAND device
>   * @cleanup: cleanup a SPI NAND device
>   *
>   * Each SPI NAND manufacturer driver should implement this interface so that
> - * NAND chips coming from this vendor can be detected and initialized properly.
> + * NAND chips coming from this vendor can be initialized properly.
>   */
>  struct spinand_manufacturer_ops {
> -	int (*detect)(struct spinand_device *spinand);
>  	int (*init)(struct spinand_device *spinand);
>  	void (*cleanup)(struct spinand_device *spinand);
>  };
> @@ -215,11 +224,16 @@ struct spinand_manufacturer_ops {
>   * struct spinand_manufacturer - SPI NAND manufacturer instance
>   * @id: manufacturer ID
>   * @name: manufacturer name
> + * @devid_len: number of bytes in device ID
> + * @chips: supported SPI NANDs under current manufacturer
> + * @nchips: number of SPI NANDs available in chips array
>   * @ops: manufacturer operations
>   */
>  struct spinand_manufacturer {
>  	u8 id;
>  	char *name;
> +	const struct spinand_info *chips;
> +	const size_t nchips;
>  	const struct spinand_manufacturer_ops *ops;
>  };
>  
> @@ -291,7 +305,7 @@ struct spinand_ecc_info {
>   */
>  struct spinand_info {
>  	const char *model;
> -	u16 devid;
> +	struct spinand_devid devid;
>  	u32 flags;
>  	struct nand_memory_organization memorg;
>  	struct nand_ecc_req eccreq;
> @@ -305,6 +319,13 @@ struct spinand_info {
>  			     unsigned int target);
>  };
>  
> +#define SPINAND_ID(__id, __len, __method)				\
> +	{								\
> +		.id = __id,						\
> +		.len = __len,						\
> +		.method = __method,					\
> +	}

That one can be turned into

#define SPINAND_ID(__method, ...)				\
	{							\
		.id = (const u8[]){ __VA_ARGS },		\
		.len = sizeof((u8[]){ __VA_ARGS }),		\
		.method = __method,				\
	}

> +
>  #define SPINAND_INFO_OP_VARIANTS(__read, __write, __update)		\
>  	{								\
>  		.read_cache = __read,					\
> @@ -451,9 +472,10 @@ static inline void spinand_set_of_node(struct spinand_device *spinand,
>  	nanddev_set_of_node(&spinand->base, np);
>  }
>  
> -int spinand_match_and_init(struct spinand_device *dev,
> +int spinand_match_and_init(struct spinand_device *spinand,
>  			   const struct spinand_info *table,
> -			   unsigned int table_size, u16 devid);
> +			   unsigned int table_size,
> +			   enum spinand_readid_method rdid_method);
>  
>  int spinand_upd_cfg(struct spinand_device *spinand, u8 mask, u8 val);
>  int spinand_select_target(struct spinand_device *spinand, unsigned int target);


WARNING: multiple messages have this Message-ID (diff)
From: Boris Brezillon <boris.brezillon@collabora.com>
To: Chuanhong Guo <gch981213@gmail.com>
Cc: Vignesh Raghavendra <vigneshr@ti.com>,
	Boris Brezillon <bbrezillon@kernel.org>,
	Richard Weinberger <richard@nod.at>,
	linux-kernel@vger.kernel.org, linux-mtd@lists.infradead.org,
	Miquel Raynal <miquel.raynal@bootlin.com>
Subject: Re: [PATCH v2] mtd: nand: spi: rework detect procedure for different read id op
Date: Fri, 10 Jan 2020 07:58:59 +0100	[thread overview]
Message-ID: <20200110075859.3edfae3a@collabora.com> (raw)
In-Reply-To: <20200110025218.1257809-1-gch981213@gmail.com>

On Fri, 10 Jan 2020 10:51:14 +0800
Chuanhong Guo <gch981213@gmail.com> wrote:


> +static int spinand_manufacturer_detect(struct spinand_device *spinand)
> +{
> +	u8 *id = spinand->id.data;
> +	int ret;
> +
> +	ret = spinand_read_id_op(spinand, 0, 0, id);
> +	if (ret)
> +		return ret;
> +	ret = spinand_manufacturer_match(spinand, SPINAND_READID_METHOD_OPCODE);
> +	if (!ret)
> +		return 0;
> +
> +	ret = spinand_read_id_op(spinand, 1, 0, id);
> +	if (ret)
> +		return ret;
> +	ret = spinand_manufacturer_match(spinand,
> +					 SPINAND_READID_METHOD_OPCODE_ADDR);
> +	if (!ret)
> +		return 0;
> +
> +	ret = spinand_read_id_op(spinand, 0, 1, id);

Hm, we should probably do only one of each read_id and iterate over all
manufacturers/chips each time instead of doing 3 read_ids per
manufacturer.

> +	if (ret)
> +		return ret;
> +	ret = spinand_manufacturer_match(spinand,
> +					 SPINAND_READID_METHOD_OPCODE_DUMMY);
> +
> +	return ret;
> +}
> +

[...]

> +/**
> + * struct spinand_devid - SPI NAND device id structure
> + * @id: device id of current chip
> + * @len: number of bytes in device id
> + * @method: method to read chip id
> + *	    There are 3 possible variants:
> + *	    SPINAND_READID_METHOD_OPCODE: chip id is returned immediately
> + *	    after read_id opcode.
> + *	    SPINAND_READID_METHOD_OPCODE_ADDR: chip id is returned after
> + *	    read_id opcode + 1-byte address.
> + *	    SPINAND_READID_METHOD_OPCODE_DUMMY: chip id is returned after
> + *	    read_id opcode + 1 dummy byte.
> + */
> +struct spinand_devid {
> +	u16 id;

Can we make that field an array of u8?

	const u8 *id;

> +	u8 len;
> +	enum spinand_readid_method method;
> +};
> +
>  /**
>   * struct manufacurer_ops - SPI NAND manufacturer specific operations
> - * @detect: detect a SPI NAND device. Every time a SPI NAND device is probed
> - *	    the core calls the struct_manufacurer_ops->detect() hook of each
> - *	    registered manufacturer until one of them return 1. Note that
> - *	    the first thing to check in this hook is that the manufacturer ID
> - *	    in struct_spinand_device->id matches the manufacturer whose
> - *	    ->detect() hook has been called. Should return 1 if there's a
> - *	    match, 0 if the manufacturer ID does not match and a negative
> - *	    error code otherwise. When true is returned, the core assumes
> - *	    that properties of the NAND chip (spinand->base.memorg and
> - *	    spinand->base.eccreq) have been filled
>   * @init: initialize a SPI NAND device
>   * @cleanup: cleanup a SPI NAND device
>   *
>   * Each SPI NAND manufacturer driver should implement this interface so that
> - * NAND chips coming from this vendor can be detected and initialized properly.
> + * NAND chips coming from this vendor can be initialized properly.
>   */
>  struct spinand_manufacturer_ops {
> -	int (*detect)(struct spinand_device *spinand);
>  	int (*init)(struct spinand_device *spinand);
>  	void (*cleanup)(struct spinand_device *spinand);
>  };
> @@ -215,11 +224,16 @@ struct spinand_manufacturer_ops {
>   * struct spinand_manufacturer - SPI NAND manufacturer instance
>   * @id: manufacturer ID
>   * @name: manufacturer name
> + * @devid_len: number of bytes in device ID
> + * @chips: supported SPI NANDs under current manufacturer
> + * @nchips: number of SPI NANDs available in chips array
>   * @ops: manufacturer operations
>   */
>  struct spinand_manufacturer {
>  	u8 id;
>  	char *name;
> +	const struct spinand_info *chips;
> +	const size_t nchips;
>  	const struct spinand_manufacturer_ops *ops;
>  };
>  
> @@ -291,7 +305,7 @@ struct spinand_ecc_info {
>   */
>  struct spinand_info {
>  	const char *model;
> -	u16 devid;
> +	struct spinand_devid devid;
>  	u32 flags;
>  	struct nand_memory_organization memorg;
>  	struct nand_ecc_req eccreq;
> @@ -305,6 +319,13 @@ struct spinand_info {
>  			     unsigned int target);
>  };
>  
> +#define SPINAND_ID(__id, __len, __method)				\
> +	{								\
> +		.id = __id,						\
> +		.len = __len,						\
> +		.method = __method,					\
> +	}

That one can be turned into

#define SPINAND_ID(__method, ...)				\
	{							\
		.id = (const u8[]){ __VA_ARGS },		\
		.len = sizeof((u8[]){ __VA_ARGS }),		\
		.method = __method,				\
	}

> +
>  #define SPINAND_INFO_OP_VARIANTS(__read, __write, __update)		\
>  	{								\
>  		.read_cache = __read,					\
> @@ -451,9 +472,10 @@ static inline void spinand_set_of_node(struct spinand_device *spinand,
>  	nanddev_set_of_node(&spinand->base, np);
>  }
>  
> -int spinand_match_and_init(struct spinand_device *dev,
> +int spinand_match_and_init(struct spinand_device *spinand,
>  			   const struct spinand_info *table,
> -			   unsigned int table_size, u16 devid);
> +			   unsigned int table_size,
> +			   enum spinand_readid_method rdid_method);
>  
>  int spinand_upd_cfg(struct spinand_device *spinand, u8 mask, u8 val);
>  int spinand_select_target(struct spinand_device *spinand, unsigned int target);


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

  reply	other threads:[~2020-01-10  6:59 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-10  2:51 [PATCH v2] mtd: nand: spi: rework detect procedure for different read id op Chuanhong Guo
2020-01-10  2:51 ` Chuanhong Guo
2020-01-10  6:58 ` Boris Brezillon [this message]
2020-01-10  6:58   ` Boris Brezillon
2020-01-10  7:34   ` Chuanhong Guo
2020-01-10  7:34     ` Chuanhong Guo
2020-01-10  8:04     ` Boris Brezillon
2020-01-10  8:04       ` Boris Brezillon
2020-01-10  8:10       ` Miquel Raynal
2020-01-10  8:10         ` Miquel Raynal
2020-01-10  8:21         ` Boris Brezillon
2020-01-10  8:21           ` 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=20200110075859.3edfae3a@collabora.com \
    --to=boris.brezillon@collabora.com \
    --cc=bbrezillon@kernel.org \
    --cc=gch981213@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mtd@lists.infradead.org \
    --cc=miquel.raynal@bootlin.com \
    --cc=richard@nod.at \
    --cc=vigneshr@ti.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.