From: Boris Brezillon <boris.brezillon@free-electrons.com>
To: Peter Pan <peterpandong@micron.com>
Cc: <richard@nod.at>, <computersforpeace@gmail.com>,
<linux-mtd@lists.infradead.org>, <peterpansjtu@gmail.com>,
<linshunquan1@hisilicon.com>
Subject: Re: [PATCH 02/11] nand: spi: create spi_nand_chip struct
Date: Tue, 21 Feb 2017 09:34:45 +0100 [thread overview]
Message-ID: <20170221093445.712ec39d@bbrezillon> (raw)
In-Reply-To: <1487664010-25926-3-git-send-email-peterpandong@micron.com>
On Tue, 21 Feb 2017 16:00:01 +0800
Peter Pan <peterpandong@micron.com> wrote:
> Create spi_nand_chip struct and helper functions.
>
> Signed-off-by: Peter Pan <peterpandong@micron.com>
> ---
> include/linux/mtd/spi-nand.h | 67 ++++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 67 insertions(+)
>
> diff --git a/include/linux/mtd/spi-nand.h b/include/linux/mtd/spi-nand.h
> index 68442e08..23b16f0 100644
> --- a/include/linux/mtd/spi-nand.h
> +++ b/include/linux/mtd/spi-nand.h
> @@ -16,6 +16,12 @@
> #ifndef __LINUX_MTD_SPI_NAND_H
> #define __LINUX_MTD_SPI_NAND_H
>
> +#include <linux/wait.h>
> +#include <linux/spinlock.h>
> +#include <linux/mtd/mtd.h>
> +#include <linux/mtd/flashchip.h>
> +#include <linux/mtd/nand.h>
> +
> /*
> * Standard SPI-NAND flash commands
> */
> @@ -109,4 +115,65 @@
> #define SPI_NAND_MT29F_ECC_7_8_BIT 0x50
> #define SPI_NAND_MT29F_ECC_UNCORR 0x20
>
> +/**
> + * struct spi_nand_chip - SPI-NAND Private Flash Chip Data
> + * @base: [INTERN] NAND device instance
Drop extra tabs after the field name, and please drop these
[INTERN/BOARDSPECIFIC] specifiers.
> + * @chip_lock: [INTERN] protection lock
> + * @name: name of the chip
> + * @wq: [INTERN] wait queue to sleep on if a SPI-NAND operation
> + * is in progress used instead of the per chip wait queue
> + * when a hw controller is available.
> + * @mfr_id: [BOARDSPECIFIC] manufacture id
> + * @dev_id: [BOARDSPECIFIC] device id
> + * @state: [INTERN] the current state of the SPI-NAND device
> + * @read_cache_op: [REPLACEABLE] Opcode of read from cache
> + * @write_cache_op: [REPLACEABLE] Opcode of program load
> + * @buf: [INTERN] buffer for read/write data
> + * @oobbuf: [INTERN] buffer for read/write oob
> + * @controller_caps: [INTERN] capacities of SPI NAND controller
> + * @size: [INTERN] the size of chip
> + * @options: [BOARDSPECIFIC] various chip options. They can partly
> + * be set to inform nand_scan about special functionality.
> + * @ecc_strength: [INTERN] ECC correctability from the datasheet.
> + * @priv: [BOARDSPECIFIC] pointer to controller data
> + */
> +struct spi_nand_chip {
s/spi_nand_chip/spinand_device/
Let's try to be consistent with the rawnand_device naming scheme. So in
general s/spi_nand/spinand/
> + struct nand_device base;
No tabs, just a single space.
> + spinlock_t chip_lock;
s/chip_lock/lock/, why do you need a spinlock here?
> + char *name;
> + wait_queue_head_t wq;
> + u8 mfr_id;
> + u8 dev_id;
Can we make it an array of u8 and then have pre-defined indexes like
#define SPINAND_MFR_ID 0
#define SPINAND_DEV_ID 1
...
> + flstate_t state;
> + u8 read_cache_op;
> + u8 write_cache_op;
Hm, so these operations are manufacturer specific.
> + u8 *buf;
> + u8 *oobbuf;
> + u32 controller_caps;
What flags do you plan to put here ^?
> + u64 size;
Isn't it already defined in nand_device?
> + u32 options;
Again, what do you plan to put in this field?
> + u32 ecc_strength;
> + void *priv;
Ok, it seems that ->priv is actually used to store controller specific
data. Please rename it or do something like:
struct {
void *priv;
} controller;
It will avoid the kind of confusion we have in the rawnand framework.
Since you also have controller caps, you could do:
struct {
u32 caps;
void *priv;
/*
* whatever is controller specific. probably a pointer
* to the SPI controller or something like that.
*/
} controller;
> +};
> +
> +static inline struct spi_nand_chip *mtd_to_spi_nand(struct mtd_info *mtd)
> +{
> + return container_of(mtd_to_nand(mtd), struct spi_nand_chip, base);
> +}
> +
> +static inline struct mtd_info *spi_nand_to_mtd(struct spi_nand_chip *chip)
> +{
> + return nand_to_mtd(&chip->base);
> +}
> +
> +static inline void *spi_nand_get_controller_data(struct spi_nand_chip *chip)
> +{
> + return chip->priv;
> +}
> +
> +static inline void spi_nand_set_controller_data(struct spi_nand_chip *chip,
> + void *priv)
> +{
> + chip->priv = priv;
> +}
> #endif /* __LINUX_MTD_SPI_NAND_H */
next prev parent reply other threads:[~2017-02-21 8:35 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-02-21 7:59 [PATCH 00/11] Introduction to SPI NAND framework Peter Pan
2017-02-21 8:00 ` [PATCH 01/11] nand: Add SPI NAND cmd set and register definition Peter Pan
2017-02-21 8:44 ` Boris Brezillon
2017-02-21 9:16 ` Peter Pan
2017-02-21 8:00 ` [PATCH 02/11] nand: spi: create spi_nand_chip struct Peter Pan
2017-02-21 8:34 ` Boris Brezillon [this message]
2017-02-21 9:08 ` Peter Pan
2017-02-21 8:00 ` [PATCH 03/11] nand: spi: Abstract SPI NAND cmd set to functions Peter Pan
2017-02-21 9:01 ` Arnaud Mouiche
2017-02-21 9:40 ` Peter Pan
2017-02-21 10:22 ` Arnaud Mouiche
2017-02-21 10:50 ` Boris Brezillon
2017-02-21 9:06 ` Boris Brezillon
2017-02-21 9:27 ` Peter Pan
2017-02-21 8:00 ` [PATCH 04/11] nand: spi: Add read function support Peter Pan
2017-02-21 9:51 ` Boris Brezillon
2017-02-21 10:06 ` Peter Pan
2017-02-21 10:39 ` Boris Brezillon
2017-02-21 11:02 ` Boris Brezillon
2017-02-21 8:00 ` [PATCH 05/11] nand: spi: Add write " Peter Pan
2017-02-21 8:00 ` [PATCH 06/11] nand: spi: Add erase " Peter Pan
2017-02-21 8:00 ` [PATCH 07/11] nand: spi: Add init/release function Peter Pan
2017-02-21 8:00 ` [PATCH 08/11] nand: spi: Add bad block support Peter Pan
2017-02-21 8:00 ` [PATCH 09/11] nand: spi: Add BBT support Peter Pan
2017-02-21 8:00 ` [PATCH 10/11] nand: spi: Add generic SPI controller support Peter Pan
2017-02-21 8:03 ` Richard Weinberger
2017-02-21 8:17 ` Peter Pan
2017-02-21 9:25 ` Arnaud Mouiche
2017-02-21 9:37 ` Peter Pan
2017-02-21 8:00 ` [PATCH 11/11] nand: spi: Add arguments check for read/write Peter Pan
2017-02-21 8:05 ` [PATCH 00/11] Introduction to SPI NAND framework Richard Weinberger
2017-02-21 8:11 ` Peter Pan
2017-02-21 8:18 ` Peter Pan
2017-02-21 8:43 ` Boris Brezillon
2017-02-21 9:15 ` Peter Pan
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=20170221093445.712ec39d@bbrezillon \
--to=boris.brezillon@free-electrons.com \
--cc=computersforpeace@gmail.com \
--cc=linshunquan1@hisilicon.com \
--cc=linux-mtd@lists.infradead.org \
--cc=peterpandong@micron.com \
--cc=peterpansjtu@gmail.com \
--cc=richard@nod.at \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox