eXcite nand flash driver
Subsystems (3)
PATCH 1/1 eXcite nand flash driver
This is a nand flash driver for the eXcite series of intelligent cameras manufactured by Basler Vision Technologies AG.
--- drivers/mtd/nand/Kconfig | 18 +++- drivers/mtd/nand/Makefile | 1 + drivers/mtd/nand/excite_nandflash.c | 259 +++++++++++++++++++++++++++++++++++ 3 files changed, 277 insertions(+), 1 deletions(-)
drivers/mtd/nand/Kconfig +17 -1
@@ -216,10 +216,26 @@ config MTD_NAND_DISKONCHIP_BBTWRITE Even if you leave this disabled, you can enable BBT writes at module load time (assuming you build diskonchip as a module) with the module parameter "inftl_bbt_write=1". - + config MTD_NAND_SHARPSL tristate "Support for NAND Flash on Sharp SL Series (C7xx + others)" depends on MTD_NAND && ARCH_PXA + +config MTD_NAND_BASLER_EXCITE + tristate "Support for NAND Flash on Basler eXcite" + depends on MTD_NAND && BASLER_EXCITE + help + This enables the driver for the NAND flash device found on the + Basler eXcite Smart Camera. If built as a module, the driver + will be named "excite_nandflash.ko". + +config MTD_NAND_BASLER_EXCITE + tristate "Support for NAND Flash on Basler eXcite" + depends on MTD_NAND && BASLER_EXCITE + help + This enables the driver for the NAND flash device found on the + Basler eXcite Smart Camera. If built as a module, the driver + will be named "excite_nandflash.ko". config MTD_NAND_CAFE tristate "NAND support for OLPC CAF� chip"
drivers/mtd/nand/Makefile +1 -0
@@ -24,6 +24,7 @@ obj-$(CONFIG_MTD_NAND_NANDSIM) += nands obj-$(CONFIG_MTD_NAND_CS553X) += cs553x_nand.o obj-$(CONFIG_MTD_NAND_NDFC) += ndfc.o obj-$(CONFIG_MTD_NAND_AT91) += at91_nand.o +obj-$(CONFIG_MTD_NAND_BASLER_EXCITE) += excite_nandflash.o nand-objs := nand_base.o nand_bbt.o cafe_nand-objs := cafe.o cafe_ecc.o
(quoted diff) +0 -0
b/drivers/mtd/nand/excite_nandflash.c
new file mode 100644
index 0000000..d683659
drivers/mtd/nand/excite_nandflash.c new file +259 -0
259 lines not on this page · raw message
Signature · 1 line
1.4.3
Just some cosmetic notes ...
drivers/mtd/nand/Kconfig config MTD_NAND_DISKONCHIP_BBTWRITE · line 219
Quoted 6 lines · Thomas Koeller
drivers/mtd/nand/Kconfig +1
-1@@ -216,10 +216,26 @@ config MTD_NAND_DISKONCHIP_BBTWRITE Even if you leave this disabled, you can enable BBT writes at module load time (assuming you build diskonchip as a module) with the module parameter "inftl_bbt_write=1". - +
This just inserts whitespace.
Review config MTD_NAND_DISKONCHIP_BBTWRITE · line 220
Quoted 1 line
(quoted diff) +0
-0tristate "NAND support for OLPC CAFÉ chip"
The accent on the E might cause problems, but I'm not sure.
drivers/mtd/nand/excite_nandflash.c line 51
Quoted 2 lines
drivers/mtd/nand/excite_nandflash.c new file +2
-0+#define io_readb (__a__) __raw_readb((__a__)) +#define io_writeb (__v__, __a__) __raw_writeb((__v__), (__a__))
I would have used an inline function. Also, aren't there functions to use IOs already? What's the reason here?
drivers/mtd/nand/excite_nandflash.c line 56
Quoted 2 lines
drivers/mtd/nand/excite_nandflash.c new file +2
-0+/* prefix for debug output */ +static const char module_id[] ="excite_nandflash" ;
I'd have used
static const char* module_id = "excite_nandflash";
except if you need the sizeof it to capture the length.
drivers/mtd/nand/excite_nandflash.c line 71
Quoted 3 lines
drivers/mtd/nand/excite_nandflash.c new file +3
-0+static inline const struct resource *excite_nand_get_resource + (struct platform_device *d,unsigned long flags,const char *basename){ +const char fmt[] ="%s_%u" ;
Here, too, is no need for a local buffer, just use a pointer.
drivers/mtd/nand/excite_nandflash.c
Quoted 4 lines
drivers/mtd/nand/excite_nandflash.c new file +4
-0+/* excite_nand_probe +* +* called by device layer when it finds a device matching +* one our driver can handled. [...]
"... when it finds a device our driver can handle."
Otherwise I'd say it looks very clean, better than quite some other stuff I have seen.
Uli
**************************************************************************************
Visit our website at <http://www.satorlaser.de/>
**************************************************************************************
Diese E-Mail einschließlich sämtlicher Anhänge ist nur für den Adressaten bestimmt und kann vertrauliche Informationen enthalten. Bitte benachrichtigen Sie den Absender umgehend, falls Sie nicht der beabsichtigte Empfänger sein sollten. Die E-Mail ist in diesem Fall zu löschen und darf weder gelesen, weitergeleitet, veröffentlicht oder anderweitig benutzt werden. E-Mails können durch Dritte gelesen werden und Viren sowie nichtautorisierte Änderungen enthalten. Sator Laser GmbH ist für diese Folgen nicht verantwortlich.
**************************************************************************************
Quoted 11 lines · Ulrich Eckhardt
Just some cosmetic notes ...
drivers/mtd/nand/Kconfig config MTD_NAND_DISKONCHIP_BBTWRITE · line 219
Quoted 6 lines · Thomas Koeller
drivers/mtd/nand/Kconfig +1
-1@@ -216,10 +216,26 @@ config MTD_NAND_DISKONCHIP_BBTWRITE Even if you leave this disabled, you can enable BBT writes at module load time (assuming you build diskonchip as a module) with the module parameter "inftl_bbt_write=1". - +This just inserts whitespace.
No, it actually _removes_ whitspace.
Quoted 4 lines
Review config MTD_NAND_DISKONCHIP_BBTWRITE · line 220
Quoted 2 lines
(quoted diff) +0
-0tristate "NAND support for OLPC CAFÉ chip"The accent on the E might cause problems, but I'm not sure.
This has been in there before.
Quoted 7 lines
drivers/mtd/nand/excite_nandflash.c line 51
Quoted 3 lines
drivers/mtd/nand/excite_nandflash.c new file +2
-0+#define io_readb (__a__) __raw_readb((__a__)) +#define io_writeb (__v__, __a__) __raw_writeb((__v__), (__a__))I would have used an inline function. Also, aren't there functions to use IOs already? What's the reason here?
Quoted 8 lines
drivers/mtd/nand/excite_nandflash.c line 56
Quoted 2 lines
drivers/mtd/nand/excite_nandflash.c new file +2
-0+/* prefix for debug output */ +static const char module_id[] ="excite_nandflash" ;I'd have used
static const char* module_id = "excite_nandflash";except if you need the sizeof it to capture the length.
Then I'd have used
static const char * const module_id = "excite_nandflash";
but what is the advantage of doing so?
Quoted 5 lines
Review config MTD_NAND_DISKONCHIP_BBTWRITE · line 227
Quoted 4 lines
(quoted diff) +2
-0+static inline const struct resource *excite_nand_get_resource + (struct platform_device *d, unsigned long flags, const char *basename){ + const char fmt[] = "%s_%u";
Quoted 8 lines
Here, too, is no need for a local buffer, just use a pointer.
drivers/mtd/nand/excite_nandflash.c
Quoted 4 lines
drivers/mtd/nand/excite_nandflash.c new file +4
-0+/* excite_nand_probe +* +* called by device layer when it finds a device matching +* one our driver can handled. [...] "... when it finds a device our driver can handle."
Right.
Quoted 6 lines
Otherwise I'd say it looks very clean, better than quite some other stuff I have seen.
Uli
Thanks for your comments!
_______________________________
Thomas Köller, Software Developer
Basler Vision Technologies
An der Strusbek 60-62
22926 Ahrensburg
Germany
Tel. +49 (0) 4102 - 463 390
Fax +49 (0) 4102 - 463 390
mailto:[email protected]
http://www.baslerweb.com
Vorstand: Dr.-Ing. Dietmar Ley (Vorsitzender) · John P. Jennings · Peter Krumhoff · Aufsichtsratsvorsitzender: Norbert Basler Basler AG · Amtsgericht Ahrensburg HRB 4090 · Ust-IdNr.: DE 135 098 121 · Steuer-Nr.: 30 292 04497
_______________________________
Quoted 20 lines · Thomas Koeller
drivers/mtd/nand/Kconfig +7
-1@@ -216,10 +216,26 @@ config MTD_NAND_DISKONCHIP_BBTWRITE Even if you leave this disabled, you can enable BBT writes at module load time (assuming you build diskonchip as a module) with the module parameter "inftl_bbt_write=1". - + config MTD_NAND_SHARPSL tristate "Support for NAND Flash on Sharp SL Series (C7xx + others)" depends on MTD_NAND && ARCH_PXA + +config MTD_NAND_BASLER_EXCITE + tristate "Support for NAND Flash on Basler eXcite" + depends on MTD_NAND && BASLER_EXCITE + help + This enables the driver for the NAND flash device found on the
drivers/mtd/nand/Kconfig config MTD_NAND_DISKONCHIP_BBTWRITE · line 238
Quoted 10 lines
drivers/mtd/nand/Kconfig +10
-0+ Basler eXcite Smart Camera. If built as a module, the driver + will be named "excite_nandflash.ko". + +config MTD_NAND_BASLER_EXCITE + tristate "Support for NAND Flash on Basler eXcite" + depends on MTD_NAND && BASLER_EXCITE + help + This enables the driver for the NAND flash device found on the + Basler eXcite Smart Camera. If built as a module, the driver + will be named "excite_nandflash.ko".
You have the same config option twice... Cut and paste error?
Quoted 6 lines
drivers/mtd/nand/excite_nandflash.c new file +0
-0
<snip>
drivers/mtd/nand/excite_nandflash.c line 51
Quoted 3 lines
drivers/mtd/nand/excite_nandflash.c new file +3
-0+ +#define io_readb (__a__) __raw_readb((__a__)) +#define io_writeb (__v__, __a__) __raw_writeb((__v__), (__a__))
Do you really need these defines? Why can't you call __raw_{readb,writeb} directly?
drivers/mtd/nand/excite_nandflash.c
Quoted 2 lines
drivers/mtd/nand/excite_nandflash.c new file +2
-0+ +typedef void __iomem *io_reg_t ;
Ugh... typdef?
<snip>
drivers/mtd/nand/excite_nandflash.c line 87
Quoted 8 lines
drivers/mtd/nand/excite_nandflash.c new file +8
-0+static inline io_reg_t +excite_nand_map_regs (struct platform_device *d,const char *basename) +{ +void *result =NULL ; +const struct resource *const r = +excite_nand_get_resource (d,IORESOURCE_MEM , basename); +if (likely (r)) + result =ioremap_nocache (r->start, r->end +1 - r->start);
Does this likely really buy you anything? I would think doing the converse (if any sort of *likely at all) would be better.
<snip>
Quoted 13 lines
+ */
drivers/mtd/nand/excite_nandflash.c new file +12
-0+static int __exit excite_nand_remove(struct device *dev) +{ +struct excite_nand_drvdata *const this =dev_get_drvdata (dev); + +dev_set_drvdata (dev,NULL ); + +if (unlikely (!this)) { +printk (KERN_ERR "%s: called %s without private data!!" , + module_id, __func__); +return -EINVAL ; + } +
drivers/mtd/nand/excite_nandflash.c line 160
Quoted 10 lines
drivers/mtd/nand/excite_nandflash.c new file +10
-0+/* first thing we need to do is release our mtd +* then go through freeing the resource used +*/ +nand_release (&this->board_mtd); + +/* free the common resources */ +if (likely (this->regs)) { +iounmap (this->regs); + this->regs =NULL ; + }
Same likely usage comment as above.
josh
Quoted 7 lines · Josh Boyer
drivers/mtd/nand/excite_nandflash.c line 160
Quoted 5 lines
drivers/mtd/nand/excite_nandflash.c new file +5
-0+/* free the common resources */ +if (likely (this->regs)) { +iounmap (this->regs); + this->regs =NULL ; + }Same likely usage comment as above.
I agree, this function will be called one or very few times, so this hint is not reasonable in this case.
Signature · 2 lines
Best regards, Artem Bityutskiy (Битюцкий Артём)
drivers/mtd/nand/excite_nandflash.c line 70
Quoted 2 lines · Thomas Koeller
drivers/mtd/nand/excite_nandflash.c new file +2
-0+static inline const struct resource *excite_nand_get_resource + (struct platform_device *d,unsigned long flags,const char *basename) {
Move curly bracket to new line.
drivers/mtd/nand/excite_nandflash.c line 71
Quoted 1 line
drivers/mtd/nand/excite_nandflash.c new file +1
-0+const char fmt[] ="%s_%u" ;
Please move the format into the snprintf
drivers/mtd/nand/excite_nandflash.c line 76
Quoted 5 lines
drivers/mtd/nand/excite_nandflash.c new file +5
-0+char buf[80 ]; + +if (unlikely + (snprintf (buf,sizeof buf, fmt, basename, d->id) >=sizeof buf)) +return NULL ;
Useless unlikely
drivers/mtd/nand/excite_nandflash.c line 85
Quoted 9 lines
drivers/mtd/nand/excite_nandflash.c new file +9
-0+return platform_get_resource_byname (d, flags, buf); +} + +static inline io_reg_t +excite_nand_map_regs (struct platform_device *d,const char *basename) +{ +void *result =NULL ; +const struct resource *const r = +excite_nand_get_resource (d,IORESOURCE_MEM , basename);
Blank line between variable declaration and code.
drivers/mtd/nand/excite_nandflash.c line 87
Quoted 2 lines
drivers/mtd/nand/excite_nandflash.c new file +2
-0+if (likely (r)) + result =ioremap_nocache (r->start, r->end +1 - r->start);
Useless likely
Quoted 13 lines
drivers/mtd/nand/excite_nandflash.c new file +11
-0+return result; +} +/* command and control functions */ +static void excite_nand_control (struct mtd_info *mtd,int cmd, +unsigned int ctrl) +{ +io_reg_t regs = + container_of(mtd, struct excite_nand_drvdata, board_mtd)->regs; +static void __iomem *tgt =NULL ; + +switch (ctrl) {
drivers/mtd/nand/excite_nandflash.c line 116
Quoted 10 lines
drivers/mtd/nand/excite_nandflash.c new file +10
-0+case NAND_CTRL_CHANGE |NAND_CTRL_CLE : + tgt = regs +EXCITE_NANDFLASH_CMD_BYTE ; +break ; +case NAND_CTRL_CHANGE |NAND_CTRL_ALE : + tgt = regs +EXCITE_NANDFLASH_ADDR_BYTE ; +break ; +case NAND_CTRL_CHANGE |NAND_NCE : + tgt = regs +EXCITE_NANDFLASH_DATA_BYTE ; +break ; + }
Err, did this ever work ? I doubt it. From nand_base.c:
chip->cmd_ctrl(mtd, page_addr, ctrl);
ctrl &= ~NAND_CTRL_CHANGE;
chip->cmd_ctrl(mtd, page_addr >> 8, ctrl); So I expect an OOPS happens on a regular base.
drivers/mtd/nand/excite_nandflash.c line 129
Quoted 4 lines
drivers/mtd/nand/excite_nandflash.c new file +4
-0+static int excite_nand_devready (struct mtd_info *mtd) +{ +struct excite_nand_drvdata *const drvdata = + container_of(mtd, struct excite_nand_drvdata, board_mtd);
Blank line missing
Quoted 18 lines
drivers/mtd/nand/excite_nandflash.c new file +18
-0+return io_readb (drvdata->regs +EXCITE_NANDFLASH_STATUS_BYTE ); +} + +/* excite_nand_remove +* +* called by device layer to remove the driver +* the binding to the mtd and all allocated +* resources are released +*/ +static int __exit excite_nand_remove(struct device *dev) +{ +struct excite_nand_drvdata *const this =dev_get_drvdata (dev); + +dev_set_drvdata (dev,NULL ); + +if (unlikely (!this)) { +printk (KERN_ERR "%s: called %s without private data!!" , + module_id, __func__);
drivers/mtd/nand/excite_nandflash.c line 157
Quoted 10 lines
drivers/mtd/nand/excite_nandflash.c new file +10
-0+return -EINVAL ; + } + +/* first thing we need to do is release our mtd +* then go through freeing the resource used +*/ +nand_release (&this->board_mtd); + +/* free the common resources */ +if (likely (this->regs)) {
Why should you ever come here with no mapping ?
tglx
Quoted 22 lines · Thomas Gleixner
Quoted 9 lines
drivers/mtd/nand/excite_nandflash.c new file +9
-0+/* command and control functions */ +static void excite_nand_control (struct mtd_info *mtd,int cmd, +unsigned int ctrl) +{ +io_reg_t regs = + container_of(mtd, struct excite_nand_drvdata, board_mtd)->regs; +static void __iomem *tgt =NULL ; + +switch (ctrl) {drivers/mtd/nand/excite_nandflash.c line 116
Quoted 10 lines
drivers/mtd/nand/excite_nandflash.c new file +10
-0+case NAND_CTRL_CHANGE |NAND_CTRL_CLE : + tgt = regs +EXCITE_NANDFLASH_CMD_BYTE ; +break ; +case NAND_CTRL_CHANGE |NAND_CTRL_ALE : + tgt = regs +EXCITE_NANDFLASH_ADDR_BYTE ; +break ; +case NAND_CTRL_CHANGE |NAND_NCE : + tgt = regs +EXCITE_NANDFLASH_DATA_BYTE ; +break ; + }Err, did this ever work ? I doubt it. From
nand_base.c:
Quoted 6 lines
chip->cmd_ctrl(mtd, page_addr, ctrl); ctrl &= ~NAND_CTRL_CHANGE; chip->cmd_ctrl(mtd, page_addr >> 8, ctrl);So I expect an OOPS happens on a regular base.
I guess it is the 'static void __iomem *tgt = NULL' part that worries you? Think about it, that value is never used.
However, I admit it is somewhat unclean, and therefore I am changing it. Updated patch follows.
tk
Quoted 3 lines · Thomas Koeller
Quoted 1 line
So I expect an OOPS happens on a regular base.
I guess it is the 'static void
__iomem*tgt = NULL' part that worries you? Think about it, that value is never used.
True.
Quoted 2 lines
However, I admit it is somewhat unclean, and therefore I am changing it. Updated patch follows.
Yes, it is confusing and looks horrible.
tglx