From: Boris Brezillon <boris.brezillon@free-electrons.com>
To: Peter Pan <peterpandong@micron.com>
Cc: <richard@nod.at>, <computersforpeace@gmail.com>,
<arnaud.mouiche@gmail.com>, <thomas.petazzoni@free-electrons.com>,
<marex@denx.de>, <cyrille.pitchen@wedev4u.fr>,
<linux-mtd@lists.infradead.org>, <peterpansjtu@gmail.com>,
<linshunquan1@hisilicon.com>
Subject: Re: [PATCH v6 10/15] nand: spi: add basic blocks for infrastructure
Date: Mon, 29 May 2017 23:51:18 +0200 [thread overview]
Message-ID: <20170529235118.0096ac2a@bbrezillon> (raw)
In-Reply-To: <1495609631-18880-11-git-send-email-peterpandong@micron.com>
On Wed, 24 May 2017 15:07:06 +0800
Peter Pan <peterpandong@micron.com> wrote:
> This is the first commit for spi nand framkework.
^ framework
> This commit is to add add basic building blocks
is adding basic ...
> for the SPI NAND infrastructure.
>
> Signed-off-by: Peter Pan <peterpandong@micron.com>
> ---
[...]
> +
> +/**
> + * devm_spinand_alloc - [SPI NAND Interface] allocate SPI NAND device instance
Let's drop those [SPI NAND Interface] specifier. It's pretty obvious
that this is part of the spi-nand API, since those symbols are exported.
> + * @dev: pointer to device model structure
> + */
> +struct spinand_device *devm_spinand_alloc(struct device *dev)
You can pass a pointer to the nand_controller object driving the
nand_device here.
> +{
> + struct spinand_device *spinand;
> + struct mtd_info *mtd;
> +
> + spinand = devm_kzalloc(dev, sizeof(*spinand), GFP_KERNEL);
> + if (!spinand)
> + return ERR_PTR(-ENOMEM);
> +
> + spinand_set_of_node(spinand, dev->of_node);
> + mutex_init(&spinand->lock);
> + spinand->dev = dev;
Hm, I don't think this is correct. The device here is likely to
represent the controller not the SPI NAND device. For the generic spi
nand controller, I agree, it's the same, but, in case you have one
controller that is attached several spi devices, it's not.
How about putting the struct device pointer in nand_controller and then
pass the controller to this spinand_alloc() function.
> + mtd = spinand_to_mtd(spinand);
> + mtd->dev.parent = dev;
> +
> + return spinand;
> +}
> +EXPORT_SYMBOL_GPL(devm_spinand_alloc);
> +
> +/**
> + * spinand_init - [SPI NAND Interface] initialize the SPI NAND device
> + * @spinand: SPI NAND device structure
> + */
> +int spinand_init(struct spinand_device *spinand)
> +{
> + struct mtd_info *mtd = spinand_to_mtd(spinand);
> + struct nand_device *nand = mtd_to_nand(mtd);
> + int ret;
> +
> + ret = spinand_detect(spinand);
> + if (ret) {
> + dev_err(spinand->dev,
> + "Detect SPI NAND failed with error %d.\n", ret);
> + goto err_out;
return ret;
> + }
I'd still prefer to move the detection step out of this _init()
function even if this implies duplicating the _detect()+_init()
sequence in all drivers. Maybe you can provide a wrapper called
spinand_detect_and_init() to do both in one go.
> +
> + spinand_set_rd_wr_op(spinand);
> +
> + /*
> + * Use kzalloc() instead of devm_kzalloc() here, beacause some drivers
> + * may use this buffer for DMA access.
> + * Memory allocated by devm_ does not guarantee DMA-safe alignment.
> + */
> + spinand->buf = kzalloc(nand_page_size(nand) +
> + nand_per_page_oobsize(nand),
> + GFP_KERNEL);
> + if (!spinand->buf) {
> + ret = -ENOMEM;
> + goto err_out;
return -ENOMEM;
> + }
> +
> + spinand->oobbuf = spinand->buf + nand_page_size(nand);
> +
> + ret = spinand_manufacturer_init(spinand);
> + if (ret) {
> + dev_err(spinand->dev,
> + "Manufacurer init SPI NAND failed with err %d.\n",
> + ret);
> + goto err_free_buf;
> + }
> +
> + mtd->name = spinand->name;
> + mtd->size = nand_size(nand);
> + mtd->erasesize = nand_eraseblock_size(nand);
> + mtd->writesize = nand_page_size(nand);
> + mtd->writebufsize = mtd->writesize;
> + mtd->owner = THIS_MODULE;
> + mtd->type = MTD_NANDFLASH;
> + mtd->flags = MTD_CAP_NANDFLASH;
> + mtd->oobsize = nand_per_page_oobsize(nand);
> + /*
> + * Right now, we don't support ECC, so let the whole oob
> + * area is available for user.
> + */
> + mtd->oobavail = mtd->oobsize;
> +
> + /* After power up, all blocks are locked, so unlock it here. */
> + spinand_lock_block(spinand, BL_ALL_UNLOCKED);
> +
> + return 0;
> +
> +err_free_buf:
> + kfree(spinand->buf);
> +err_out:
You can get rid of err_out.
> + return ret;
> +}
> +EXPORT_SYMBOL_GPL(spinand_init);
> +
next prev parent reply other threads:[~2017-05-29 21:51 UTC|newest]
Thread overview: 65+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-05-24 7:06 [PATCH v6 00/15] A SPI NAND framework under generic NAND framework Peter Pan
2017-05-24 7:06 ` [PATCH v6 01/15] mtd: nand: Rename nand.h into rawnand.h Peter Pan
2017-05-24 7:06 ` [PATCH v6 02/15] mtd: nand: move raw NAND related code to the raw/ subdir Peter Pan
2017-05-24 7:06 ` [PATCH v6 03/15] mtd: nand: add a nand.h file to expose basic NAND stuff Peter Pan
2017-05-29 20:14 ` Boris Brezillon
2017-05-24 7:07 ` [PATCH v6 04/15] mtd: nand: raw: prefix conflicting names with nandcchip instead of nand Peter Pan
2017-05-29 20:22 ` Boris Brezillon
2017-05-24 7:07 ` [PATCH v6 05/15] mtd: nand: raw: create struct rawnand_device Peter Pan
2017-05-29 21:05 ` Boris Brezillon
2017-05-24 7:07 ` [PATCH v6 06/15] mtd: nand: raw: make BBT code more generic Peter Pan
2017-05-24 7:07 ` [PATCH v6 07/15] mtd: nand: move BBT code to drivers/mtd/nand/ Peter Pan
2017-05-24 7:07 ` [PATCH v6 08/15] mtd: nand: Add the page iterator concept Peter Pan
2017-05-29 21:12 ` Boris Brezillon
2017-05-24 7:07 ` [PATCH v6 09/15] mtd: nand: make sure mtd_oob_ops consistent in bbt Peter Pan
2017-05-29 21:06 ` Boris Brezillon
2017-05-24 7:07 ` [PATCH v6 10/15] nand: spi: add basic blocks for infrastructure Peter Pan
2017-05-29 21:51 ` Boris Brezillon [this message]
2017-05-31 7:02 ` Peter Pan 潘栋 (peterpandong)
2017-05-31 21:45 ` Cyrille Pitchen
2017-06-01 7:24 ` Boris Brezillon
2017-05-24 7:07 ` [PATCH v6 11/15] nand: spi: add basic operations support Peter Pan
2017-05-29 22:11 ` Boris Brezillon
2017-05-31 6:51 ` Peter Pan 潘栋 (peterpandong)
2017-05-31 10:02 ` Boris Brezillon
2017-06-27 20:15 ` Boris Brezillon
2017-06-28 9:41 ` Arnaud Mouiche
2017-06-28 11:32 ` Boris Brezillon
2017-06-29 5:45 ` Peter Pan 潘栋 (peterpandong)
2017-06-29 6:07 ` Peter Pan 潘栋 (peterpandong)
2017-06-29 7:05 ` Arnaud Mouiche
2017-10-11 13:35 ` Boris Brezillon
2017-10-12 1:28 ` Peter Pan
2017-05-24 7:07 ` [PATCH v6 12/15] nand: spi: Add bad block support Peter Pan
2017-05-24 7:07 ` [PATCH v6 13/15] nand: spi: add Micron spi nand support Peter Pan
2017-05-24 7:07 ` [PATCH v6 14/15] nand: spi: Add generic SPI controller support Peter Pan
2017-05-24 7:07 ` [PATCH v6 15/15] MAINTAINERS: Add SPI NAND entry Peter Pan
2017-05-29 20:59 ` [PATCH v6 00/15] A SPI NAND framework under generic NAND framework Boris Brezillon
2017-12-04 13:32 ` Frieder Schrempf
2017-12-04 14:05 ` Boris Brezillon
2017-12-05 1:35 ` Peter Pan 潘栋 (peterpandong)
2017-12-05 12:58 ` Boris Brezillon
2017-12-05 13:03 ` Boris Brezillon
2017-12-12 9:58 ` Frieder Schrempf
2017-12-13 21:27 ` Boris Brezillon
2017-12-14 6:15 ` Peter Pan
2017-12-14 7:50 ` Boris Brezillon
2017-12-14 8:06 ` Peter Pan
2017-12-14 14:39 ` Frieder Schrempf
2017-12-14 14:43 ` Frieder Schrempf
2017-12-14 15:38 ` Boris Brezillon
2017-12-15 1:08 ` Peter Pan
2017-12-15 1:21 ` Peter Pan
2017-12-21 11:48 ` Frieder Schrempf
2017-12-21 13:01 ` Boris Brezillon
2017-12-21 13:54 ` Frieder Schrempf
2017-12-22 0:49 ` Peter Pan
2017-12-22 6:37 ` Peter Pan
2017-12-22 8:28 ` Boris Brezillon
2017-12-22 13:51 ` Boris Brezillon
2018-01-02 2:51 ` Peter Pan
2018-01-03 16:46 ` Boris Brezillon
2018-01-04 2:01 ` Peter Pan
2018-01-08 22:07 ` Boris Brezillon
2017-12-15 2:35 ` Peter Pan
2017-12-15 12:41 ` 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=20170529235118.0096ac2a@bbrezillon \
--to=boris.brezillon@free-electrons.com \
--cc=arnaud.mouiche@gmail.com \
--cc=computersforpeace@gmail.com \
--cc=cyrille.pitchen@wedev4u.fr \
--cc=linshunquan1@hisilicon.com \
--cc=linux-mtd@lists.infradead.org \
--cc=marex@denx.de \
--cc=peterpandong@micron.com \
--cc=peterpansjtu@gmail.com \
--cc=richard@nod.at \
--cc=thomas.petazzoni@free-electrons.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.