From: Zhou Wang <wangzhou.bry-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
To: Arnd Bergmann <arnd-r2nGTMty4D4@public.gmane.org>
Cc: linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org,
Rob Herring <robh+dt-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>,
Pawel Moll <pawel.moll-5wv7dgnIgG8@public.gmane.org>,
Mark Rutland <mark.rutland-5wv7dgnIgG8@public.gmane.org>,
Ian Campbell
<ijc+devicetree-KcIKpvwj1kUDXYZnReoRVg@public.gmane.org>,
Kumar Gala <galak-sgV2jX0FEOL9JmXXK+q4OQ@public.gmane.org>,
Russell King <linux-lFZ/pmaqli7XmaaqVzeoHQ@public.gmane.org>,
David Woodhouse <dwmw2-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org>,
Brian Norris
<computersforpeace-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>,
Grant Likely
<grant.likely-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>,
Ezequiel Garcia
<ezequiel.garcia-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8@public.gmane.org>,
Pekon Gupta <pekon-l0cyMroinI0@public.gmane.org>,
Artem Bityutskiy
<artem.bityutskiy-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>,
Alexander Shiyan <shc_work-JGs/UdohzUI@public.gmane.org>,
Ivan Khoronzhuk <ivan.khoronzhuk-l0cyMroinI0@public.gmane.org>,
Jussi Kivilinna <jussi.kivilinna-X3B1VOXEql0@public.gmane.org>,
Joern Engel <joern-PCqxUs/MD9bYtjvyW6yDsg@public.gmane.org>,
Randy Dunlap <rdunlap-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org>,
devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
linux-mtd-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org,
linux-doc-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
caizhiyong-hv44wF8Li93QT0dZR+AlfA@public.gmane.org,
wangzhou1-C8/M+/jPZTeaMJb+Lgu22Q@public.gmane.org
Subject: Re: [PATCH 2/3] mtd: hisilicon: add a new nand controller driver for hisilicon hip04 Soc
Date: Wed, 02 Jul 2014 10:07:56 +0800 [thread overview]
Message-ID: <53B3697C.1090602@gmail.com> (raw)
In-Reply-To: <6920327.DpBe6vKVPa@wuerfel>
On 2014年06月30日 17:00, Arnd Bergmann wrote:
> Overall a very nice driver. I didn't find any real bugs, but a few things
> that could be changed for readability and micro-optimizations:
>
> On Monday 30 June 2014 16:03:28 Zhou Wang wrote:
>
>> +#define hinfc_read(_host, _reg) readl(_host->iobase + (_reg))
>> +#define hinfc_write(_host, _value, _reg)\
>> + writel((_value), _host->iobase + (_reg))
>
> I'd recommend making these inline functions rather than macros.
>
I will change above macros to inline functions, thanks.
>> +struct hinfc_host {
>> + struct nand_chip *chip;
>> + struct mtd_info *mtd;
>
> I notice that you allocate the nand_chip and mtd_info together
> with the hinfc_host and then assign these pointers. A preferred
> method is normally to just embed the structures in this case:
>
> struct hinfc_host {
> struct nand_chip chip;
> struct mtd_info mtd;
>
> so you avoid the pointer overhead, and can go back from these
> two structures to the hinfc_host using container_of().
>
It is better to embed chip and mtd in host, I will change this, thanks.
>> + struct device *dev;
>> + void __iomem *iobase;
>> + struct completion cmd_complete;
>> + unsigned int offset;
>> + unsigned int command;
>> + int chipselect;
>> + unsigned int addr_cycle;
>> + unsigned int addr_value[2];
>> + unsigned int cache_addr_value[2];
>> + char *buffer;
>> + dma_addr_t dma_buffer;
>> + dma_addr_t dma_oob;
>> + int version;
>> + unsigned int ecc_bits;
>> + unsigned int irq_status; /* interrupt status */
>> +
>> + int (*send_cmd_pageprog)(struct hinfc_host *host);
>> + int (*send_cmd_status)(struct hinfc_host *host);
>> + int (*send_cmd_readstart)(struct hinfc_host *host);
>> + int (*send_cmd_erase)(struct hinfc_host *host);
>> + int (*send_cmd_readid)(struct hinfc_host *host);
>> + int (*send_cmd_reset)(struct hinfc_host *host, int chipselect);
>> +};
>
> Why do you need function pointers here? The current version of the
> driver you posted always assigns these to the same functions, so
> it would be more efficient to just call those directly.
>
> If you plan to add another variant later that uses a different set
> of functions here, you can add the function pointers then, in a
> separate patch. Also, a common style element is to have a separate
> constant structure with the function pointers:
>
> const struct hinfc_host_ops ops = {
> .send_cmd_pageprog = hisi_nfc_send_cmd_pageprog,
> ...
> };
>
> if you actually end up needing function pointers. That simplifies
> the code a bit and is slightly more robust to attacks overwriting
> the function pointers.
>
I will move above function pointers out of host and directly call the
functions, thanks for your good comment.
>> +
>> +void wait_controller_finished(struct hinfc_host *host)
>> +{
>> + unsigned long timeout = jiffies + HINFC504_NFC_TIMEOUT;
>> + int val;
>> +
>> + while (time_before(jiffies, timeout)) {
>> + val = hinfc_read(host, HINFC504_STATUS);
>> + if (host->command == NAND_CMD_ERASE2) {
>> + /* nfc is ready */
>> + while (!(val & HINFC504_READY)) {
>> + usleep_range(500, 1000);
>> + val = hinfc_read(host, HINFC504_STATUS);
>> + }
>> + return;
>> + } else {
>> + if (val & HINFC504_READY)
>> + return;
>> + }
>> + }
>> +
>> + /* wait cmd timeout */
>> + dev_err(host->dev, "Wait NAND controller exec cmd timeout.\n");
>> +}
>
> Since the timeout is much bigger than the wait time here, I guess you
> can use a wider range for the usleep_range(), e.g.
>
> usleep_range(500, 50000);
>
> which is nicer to other tasks. You will normally be woken up much earlier.
>
> Arnd
>
As I know that the operating time of NAND flash erasure is about
ms-level, so I set sleep time as usleep_range(500, 1000) here. And the
timeout means that relative operations don't finish in this time, so
maybe there is something wrong with the operations. In normal situation,
after detecting the operation finished, the above function will return
before timeout arriving.
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
next prev parent reply other threads:[~2014-07-02 2:07 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-06-30 8:03 [PATCH 0/3] mtd: hisilicon: add a new driver for NAND controller of hisilicon hip04 Soc Zhou Wang
2014-06-30 8:03 ` [PATCH 1/3] mtd: hisilicon: add device tree node for nand controller Zhou Wang
2014-07-09 7:08 ` Jerome FORISSIER
2014-07-11 2:40 ` Zhou Wang
2014-06-30 8:03 ` [PATCH 2/3] mtd: hisilicon: add a new nand controller driver for hisilicon hip04 Soc Zhou Wang
2014-06-30 9:00 ` Arnd Bergmann
2014-06-30 9:59 ` Caizhiyong
2014-07-02 2:12 ` Zhou Wang
2014-07-02 2:07 ` Zhou Wang [this message]
2014-06-30 9:45 ` Ivan Khoronzhuk
2014-07-02 2:09 ` Zhou Wang
2014-06-30 10:00 ` Mark Rutland
2014-07-02 2:15 ` Zhou Wang
2014-06-30 8:03 ` [PATCH 3/3] mtd: hisilicon: add device tree binding documentation Zhou Wang
2014-06-30 9:52 ` Mark Rutland
2014-07-02 2:46 ` Zhou Wang
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=53B3697C.1090602@gmail.com \
--to=wangzhou.bry-re5jqeeqqe8avxtiumwx3w@public.gmane.org \
--cc=arnd-r2nGTMty4D4@public.gmane.org \
--cc=artem.bityutskiy-VuQAYsv1563Yd54FQh9/CA@public.gmane.org \
--cc=caizhiyong-hv44wF8Li93QT0dZR+AlfA@public.gmane.org \
--cc=computersforpeace-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
--cc=devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=dwmw2-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org \
--cc=ezequiel.garcia-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8@public.gmane.org \
--cc=galak-sgV2jX0FEOL9JmXXK+q4OQ@public.gmane.org \
--cc=grant.likely-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org \
--cc=ijc+devicetree-KcIKpvwj1kUDXYZnReoRVg@public.gmane.org \
--cc=ivan.khoronzhuk-l0cyMroinI0@public.gmane.org \
--cc=joern-PCqxUs/MD9bYtjvyW6yDsg@public.gmane.org \
--cc=jussi.kivilinna-X3B1VOXEql0@public.gmane.org \
--cc=linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org \
--cc=linux-doc-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=linux-lFZ/pmaqli7XmaaqVzeoHQ@public.gmane.org \
--cc=linux-mtd-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org \
--cc=mark.rutland-5wv7dgnIgG8@public.gmane.org \
--cc=pawel.moll-5wv7dgnIgG8@public.gmane.org \
--cc=pekon-l0cyMroinI0@public.gmane.org \
--cc=rdunlap-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org \
--cc=robh+dt-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org \
--cc=shc_work-JGs/UdohzUI@public.gmane.org \
--cc=wangzhou1-C8/M+/jPZTeaMJb+Lgu22Q@public.gmane.org \
/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;
as well as URLs for NNTP newsgroup(s).