tegra: Add NAND flash support
Subsystems (5)
cover tegra: Add NAND flash support
This series adds NAND flash support to Tegra and enables it on Seaboard.
Included here is a proposed device tree binding which I'm sure will stretch some eyes. The binding includes information about the NAND controller as well as the connected NAND device. The Seaboard has a Hynix HY27UF4G2B.
The driver supports ECC-based access and uses DMA and NAND acceleration features of the Tegra SOC to provide access at reasonable speed.
Jim Lin (1):
tegra: nand: Add Tegra NAND driver
Simon Glass (5):
fdt: Add debugging to fdtdec_get_int/addr()
tegra: Add NAND support to funcmux
tegra: fdt: Add NAND controller binding and definitions
tegra: fdt: Add NAND definitions to fdt
tegra: Enable NAND on Seaboard
arch/arm/cpu/armv7/tegra2/funcmux.c | 7 + arch/arm/dts/tegra20.dtsi | 7 +- arch/arm/include/asm/arch-tegra2/funcmux.h | 3 + arch/arm/include/asm/arch-tegra2/tegra2.h | 1 + board/nvidia/dts/tegra2-seaboard.dts | 15 + doc/device-tree-bindings/nand/nvidia-nand.txt | 68 ++ drivers/mtd/nand/Makefile | 1 + drivers/mtd/nand/tegra2_nand.c | 1074 +++++++++++++++++++++++++ drivers/mtd/nand/tegra2_nand.h | 303 +++++++ include/configs/seaboard.h | 9 + include/fdtdec.h | 1 + lib/fdtdec.c | 23 +- 12 files changed, 1505 insertions(+), 7 deletions(-) create mode 100644 doc/device-tree-bindings/nand/nvidia-nand.txt create mode 100644 drivers/mtd/nand/tegra2_nand.c create mode 100644 drivers/mtd/nand/tegra2_nand.h
Signature · 1 line
1.7.7.3
A message that is not in the archive (sent off-list or not yet received): 1326496256-5559-1-git-send-email-sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org
PATCH 1/6 fdt: Add debugging to fdtdec_get_int/addr()
The new debugging shows the value of integers and addresses read from the device tree.
--- lib/fdtdec.c | 22 ++++++++++++++++------ 1 files changed, 16 insertions(+), 6 deletions(-)
lib/fdtdec.c +16 -6
@@ -77,11 +77,16 @@ fdt_addr_t fdtdec_get_addr(const void *blob, int node,const fdt_addr_t *cell;int len; -debug ("get_addr: %s\n" , prop_name); +debug ("%s: %s\n" , __func__, prop_name); cell =fdt_getprop (blob, node, prop_name, &len);if (cell && (len ==sizeof (fdt_addr_t) || - len ==sizeof (fdt_addr_t) *2 )) -return fdt_addr_to_cpu (*cell); + len ==sizeof (fdt_addr_t) *2 )) { +fdt_addr_t addr =fdt_addr_to_cpu (*cell); + +debug ("%p\n" , (void *)addr); +return addr; + } +debug ("(not found)\n" );return FDT_ADDR_T_NONE ; }
@@ -91,10 +96,15 @@ s32 fdtdec_get_int(const void *blob, int node, const char *prop_name,const s32 *cell;int len; -debug ("get_size: %s\n" , prop_name); +debug ("%s: %s: " , __func__, prop_name); cell =fdt_getprop (blob, node, prop_name, &len); -if (cell && len >=sizeof (s32)) -return fdt32_to_cpu (cell[0 ]); +if (cell && len >=sizeof (s32)) { +s32 val =fdt32_to_cpu (cell[0 ]); + +debug ("%#x (%d)\n" , val, val); +return val; + } +debug ("(not found)\n" );return default_val; }
Signature · 1 line
1.7.7.3
PATCH 4/6 tegra: fdt: Add NAND definitions to fdt
In reply to a message not in the archiveAdd a flash node to handle the NAND, including memory timings and page / block size information.
--- board/nvidia/dts/tegra2-seaboard.dts | 15 +++++++++++++++ 1 files changed, 15 insertions(+), 0 deletions(-)
board/nvidia/dts/tegra2-seaboard.dts +15 -0
@@ -125,4 +125,19 @@ 0x00000000 0x00000000 0x00000000 0x00000000 >; }; }; + + nand-controller@0x70008000 { + wp-gpios = <&gpio 59 0>; /* PH3 */ + width = <8>; + nvidia,timing = <26 100 20 80 20 10 12 10 70>; + nand@0 { + compatible = "hynix,hy27uf4g2b", "nand-flash"; + page-data-bytes = <2048>; + tag-ecc-bytes = <4>; + tag-bytes = <20>; + data-ecc-bytes = <36>; + skipped-spare-bytes = <4>; + page-spare-bytes = <64>; + }; + }; };
Signature · 1 line
1.7.7.3
PATCH 2/6 tegra: Add NAND support to funcmux
In reply to Simon GlassAdd selection of NAND flash pins to the funcmux.
--- arch/arm/cpu/armv7/tegra2/funcmux.c | 7 +++++++ arch/arm/include/asm/arch-tegra2/funcmux.h | 3 +++ 2 files changed, 10 insertions(+), 0 deletions(-)
arch/arm/cpu/armv7/tegra2/funcmux.c +7 -0
@@ -156,6 +156,13 @@ int funcmux_select(enum periph_id id, int config) }break ; +case PERIPH_ID_NDFLASH : +if (config ==FUNCMUX_NDFLASH_ATC ) { +pinmux_set_func (PINGRP_ATC ,PMUX_FUNC_NAND ); +pinmux_tristate_disable (PINGRP_ATC ); + } +break ; +default :debug ("%s: invalid periph_id %d" , __func__, id);return -1 ;
arch/arm/include/asm/arch-tegra2/funcmux.h +3 -0
@@ -47,6 +47,9 @@ enum {FUNCMUX_SDMMC4_ATC_ATD_8BIT =0 ,FUNCMUX_SDMMC4_ATB_GMA_4_BIT ,FUNCMUX_SDMMC4_ATB_GMA_GME_8_BIT , + +/* NAND flags */ + FUNCMUX_NDFLASH_ATC = 0, };/**
Signature · 1 line
1.7.7.3
PATCH 2/6 tegra: Add NAND support to funcmux
Quoted 3 lines · Simon Glass
Add selection of NAND flash pins to the funcmux.
Signed-off-by Simon Glass <[email protected]>
Signature · 1 line
nvpublic
PATCH 3/6 tegra: fdt: Add NAND controller binding and definitions
In reply to Simon GlassAdd a NAND controller along with a bindings file for review.
--- arch/arm/dts/tegra20.dtsi | 7 ++- doc/device-tree-bindings/nand/nvidia-nand.txt | 68 +++++++++++++++++++++++++ 2 files changed, 74 insertions(+), 1 deletions(-) create mode 100644 doc/device-tree-bindings/nand/nvidia-nand.txt
arch/arm/dts/tegra20.dtsi +6 -1
@@ -210,5 +210,10 @@ reg = <0x7000f400 0x200>; }; + nand: nand-controller@0x70008000 { + #address-cells = <0>; + #size-cells = <0>; + compatible = "nvidia,tegra20-nand"; + reg = <0x70008000 0x100>; + }; }; -
doc/device-tree-bindings/nand/nvidia-nand.txt new file +68 -0
68 lines not on this page · raw message
Signature · 1 line
1.7.7.3
A message that is not in the archive (sent off-list or not yet received): 1326496256-5559-4-git-send-email-sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org
Re: [PATCH 3/6] tegra: fdt: Add NAND controller binding and definitions
Quoted 1 line · Simon Glass
Add a NAND controller along with a bindings file for review.
A few questions to start with:
Quoted 13 lines
doc/device-tree-bindings/nand/nvidia-nand.txt +11
-0+NAND Flash +---------- + +(there isn't yet a generic binding in Linux, so this describes what is in +U-Boot) + +The device node for a NAND flash device is as described in the document +"Open Firmware Recommended Practice : Universal Serial Bus" with the +following modifications and additions : + +Required properties :
doc/device-tree-bindings/nand/nvidia-nand.txt line 21
Quoted 10 lines
doc/device-tree-bindings/nand/nvidia-nand.txt +10
-0+ - compatible : Should be "manufacture,device", "nand-flash" + - page-data-bytes : Number of bytes in the data area + - page-spare-bytes : * Number of bytes in spare area + spare area = skipped-spare-bytes + data-ecc-bytes + tag-bytes + + tag-ecc-bytes + - skipped-spare-bytes : Number of bytes to skip at start of spare area + (these are typically used for bad block maintenance) + - data-ecc-bytes : Number of ECC bytes for data area + - tag-bytes :Number of tag bytes in spare area + - tag-ecc-bytes : Number ECC bytes to be generated for tag bytes
Are any of those values really needed?
I looked through all the NAND references I could find in the Linux kernel in arch/*/boot/dts/* and none of them seem to have this kind of information.
Looking at the drivers, they execute some form of identification command on the NAND device which gives back a device ID, which is then looked up in a table of known devices to give the information above.
I checked the Tegra NAND driver that's in the kernel chromeos-3.0 branch, and it does the same thing, albeit it open-codes some of the identification routines rather than just calling into the common code.
Judging by arch/*/boot/dts/*, it is standard practice to have a node for the NAND device itself though; it's used to house (optional) partition definitions. In the kernel, Documentation/devicetree/bindings/mtd/mtd-physmap.txt discusses the format of these partition nodes, and e.g. arch/powerpc/boot/dts/canyonlands.dts (amongst many) uses this on NAND.
Quoted 13 lines
doc/device-tree-bindings/nand/nvidia-nand.txt +13
-0+Nvidia NAND Controller +---------------------- + +The device node for a NAND flash controller is as described in the document +"Open Firmware Recommended Practice : Universal Serial Bus" with the +following modifications and additions : + +Optional properties: + +wp-gpio : GPIO of write-protect line, three cells in the format: + phandle, parameter, flags +width : bus width of the NAND device in bits +
doc/device-tree-bindings/nand/nvidia-nand.txt line 50
Quoted 10 lines
doc/device-tree-bindings/nand/nvidia-nand.txt +10
-0+For now here is something specific to the Nvidia controller, with naming +based on Nvidia's original (non-fdt) NAND driver: + + - nvidia,nand-timing : Timing parameters for the NAND. Each is in ns. + Order is: MAX_TRP_TREA, TWB, Max(tCS, tCH, tALS, tALH), + TWHR, Max(tCS, tCH, tALS, tALH), TWH, TWP, TRH, TADL + + MAX_TRP_TREA is: + non-EDO mode: Max(tRP, tREA) + 6ns + EDO mode: tRP timing
At first glance, it seems reasonable to have this in the NAND node; it's certainly impossible to probe the timing parameters. Since NAND is so standardized though, I wonder if there is a standard set of timing parameters so that we could have a standard device tree binding for this?
Quoted 17 lines
doc/device-tree-bindings/nand/nvidia-nand.txt +17
-0+Example: + +nand-controller@0x70008000 { + compatible = "nvidia,tegra20-nand"; + wp-gpios = <&gpio 59 0>; /* PH3 */ + width = <8>; + nvidia,timing = <26 100 20 80 20 10 12 10 70>; + nand@0 { + compatible = "hynix,hy27uf4g2b", "nand-flash"; + page-data-bytes = <2048>; + tag-ecc-bytes = <4>; + tag-bytes = <20>; + data-ecc-bytes = <36>; + skipped-spare-bytes = <4>; + page-spare-bytes = <64>; + }; +};
Signature · 1 line
nvpublic
Re: [PATCH 3/6] tegra: fdt: Add NAND controller binding and definitions
Hi Stephen,
Quoted 35 lines · Stephen Warren
Quoted 1 line · Simon Glass
Add a NAND controller along with a bindings file for review.
A few questions to start with:
Quoted 13 lines
doc/device-tree-bindings/nand/nvidia-nand.txt +11
-0+NAND Flash +---------- + +(there isn't yet a generic binding in Linux, so this describes what is in +U-Boot) + +The device node for a NAND flash device is as described in the document +"Open Firmware Recommended Practice : Universal Serial Bus" with the +following modifications and additions : + +Required properties :doc/device-tree-bindings/nand/nvidia-nand.txt line 21
Quoted 10 lines
doc/device-tree-bindings/nand/nvidia-nand.txt +10
-0+ - compatible : Should be "manufacture,device", "nand-flash" + - page-data-bytes : Number of bytes in the data area + - page-spare-bytes : * Number of bytes in spare area + spare area = skipped-spare-bytes + data-ecc-bytes + tag-bytes + + tag-ecc-bytes + - skipped-spare-bytes : Number of bytes to skip at start of spare area + (these are typically used for bad block maintenance) + - data-ecc-bytes : Number of ECC bytes for data area + - tag-bytes :Number of tag bytes in spare area + - tag-ecc-bytes : Number ECC bytes to be generated for tag bytesAre any of those values really needed?
I looked through all the NAND references I could find in the Linux kernel in
arch/*/boot/dts/*and none of them seem to have this kind of information.
Quoted 7 lines
Looking at the drivers, they execute some form of identification command on the NAND device which gives back a device ID, which is then looked up in a table of known devices to give the information above.
I checked the Tegra NAND driver that's in the kernel chromeos-3.0 branch, and it does the same thing, albeit it open-codes some of the identification routines rather than just calling into the common code.
Well that's pretty grim I think. That code should try to use the ONFi way if it is available and supported, or provide a mechanism to configure it (via device tree) if not / preferred.
U-Boot does have the same ID lookup feature for the mtd layer, but it only has page size, block size and bus width.
I do wonder why this driver cannot take more of the information it needs from the upper levels. Admittedly not all of the info is there, but it could perhaps be inferred.
Quoted 7 lines
Judging by
arch/*/boot/dts/*, it is standard practice to have a node for the NAND device itself though; it's used to house (optional) partition definitions. In the kernel,Documentation/devicetree/bindings/mtd/mtd-physmap.txtdiscusses the format of these partition nodes, and e.g.arch/powerpc/boot/dts/canyonlands.dts(amongst many) uses this on NAND.
Yes.
Quoted 21 lines
Quoted 21 lines
doc/device-tree-bindings/nand/nvidia-nand.txt +20
-0+Nvidia NAND Controller +---------------------- + +The device node for a NAND flash controller is as described in the document +"Open Firmware Recommended Practice : Universal Serial Bus" with the +following modifications and additions : + +Optional properties: + +wp-gpio : GPIO of write-protect line, three cells in the format: + phandle, parameter, flags +width : bus width of the NAND device in bits + +For now here is something specific to the Nvidia controller, with naming +based on Nvidia's original (non-fdt) NAND driver: + + - nvidia,nand-timing : Timing parameters for the NAND. Each is in ns. + Order is: MAX_TRP_TREA, TWB, Max(tCS, tCH, tALS, tALH), + TWHR, Max(tCS, tCH, tALS, tALH), TWH, TWP, TRH, TADL +
Quoted 8 lines
Quoted 3 lines
+
MAX_TRP_TREAis:
+ non-EDO mode:Max(tRP, tREA)+ 6ns
+ EDO mode: tRP timingAt first glance, it seems reasonable to have this in the NAND node; it's certainly impossible to probe the timing parameters. Since NAND is so standardized though, I wonder if there is a standard set of timing parameters so that we could have a standard device tree binding for this?
The closest datasheet I could find was this:
http://www.hynix.com/datasheet/pdf/flash/HY27(U_S)F(08_16)1G2M%20Series(Rev1.1).pdf
It has a table on p21 with 32 timing parameters.
But what we want here is the timings for the Tegra NAND controller. Every controller will have a different take on these parameters - some will be ignored, some added together, etc. So I think it is better to think in terms of what the controller needs rather than getting sidetracked on some average of all the NAND datasheets.
Quoted 13 lines
Quoted 13 lines
doc/device-tree-bindings/nand/nvidia-nand.txt +12
-0+Example: + +nand-controller@0x70008000 { + compatible = "nvidia,tegra20-nand"; + wp-gpios = <&gpio 59 0>; /* PH3 */ + width = <8>; + nvidia,timing = <26 100 20 80 20 10 12 10 70>; + nand@0 { + compatible = "hynix,hy27uf4g2b", "nand-flash"; + page-data-bytes = <2048>; + tag-ecc-bytes = <4>; + tag-bytes = <20>;
Quoted 8 lines
Quoted 5 lines
+ data-ecc-bytes = <36>;
+ skipped-spare-bytes = <4>;
+ page-spare-bytes = <64>;
+ };
+};--
nvpublic
Regards,
Simon
PATCH 5/6 tegra: nand: Add Tegra NAND driver
In reply to Simon GlassFrom: Jim Lin <[email protected]>
A device tree is used to configure the NAND, including memory timings and block/pages sizes.
If this node is not present or is disabled, then NAND will not be initialized.
--- arch/arm/include/asm/arch-tegra2/tegra2.h | 1 + drivers/mtd/nand/Makefile | 1 + drivers/mtd/nand/tegra2_nand.c | 1074 +++++++++++++++++++++++++++++ drivers/mtd/nand/tegra2_nand.h | 303 ++++++++ include/fdtdec.h | 1 + lib/fdtdec.c | 1 + 6 files changed, 1381 insertions(+), 0 deletions(-) create mode 100644 drivers/mtd/nand/tegra2_nand.c create mode 100644 drivers/mtd/nand/tegra2_nand.h
arch/arm/include/asm/arch-tegra2/tegra2.h +1 -0
@@ -39,6 +39,7 @@#define NV_PA_APB_UARTC_BASE (NV_PA_APB_MISC_BASE + 0x6200)#define NV_PA_APB_UARTD_BASE (NV_PA_APB_MISC_BASE + 0x6300)#define NV_PA_APB_UARTE_BASE (NV_PA_APB_MISC_BASE + 0x6400) +#define TEGRA2_NAND_BASE (NV_PA_APB_MISC_BASE + 0x8000)#define TEGRA2_SPI_BASE (NV_PA_APB_MISC_BASE + 0xC380)#define TEGRA2_PMC_BASE (NV_PA_APB_MISC_BASE + 0xE400)#define TEGRA2_FUSE_BASE (NV_PA_APB_MISC_BASE + 0xF800)
drivers/mtd/nand/Makefile +1 -0
@@ -60,6 +60,7 @@ COBJS-$(CONFIG_NAND_NOMADIK) += nomadik.o COBJS-$(CONFIG_NAND_S3C2410) += s3c2410_nand.o COBJS-$(CONFIG_NAND_S3C64XX) += s3c64xx.o COBJS-$(CONFIG_NAND_SPEAR) += spr_nand.o +COBJS-$(CONFIG_TEGRA2_NAND) += tegra2_nand.o COBJS-$(CONFIG_NAND_OMAP_GPMC) += omap_gpmc.o COBJS-$(CONFIG_NAND_PLAT) += nand_plat.o endif
drivers/mtd/nand/tegra2_nand.c new file +1074 -0
1,074 lines not on this page · raw message
drivers/mtd/nand/tegra2_nand.h new file +303 -0
303 lines not on this page · raw message
include/fdtdec.h +1 -0
@@ -62,6 +62,7 @@ enum fdt_compat_id {COMPAT_NVIDIA_TEGRA20_DVC ,/* Tegra2 dvc (really just i2c) */ COMPAT_NVIDIA_TEGRA20_EMC ,/* Tegra2 memory controller */ COMPAT_NVIDIA_TEGRA20_EMC_TABLE ,/* Tegra2 memory timing table */ +COMPAT_NVIDIA_TEGRA20_NAND ,/* Tegra2 NAND controller */ COMPAT_COUNT, };
lib/fdtdec.c +1 -0
@@ -42,6 +42,7 @@ static const char * const compat_names[COMPAT_COUNT] = {COMPAT (NVIDIA_TEGRA20_DVC ,"nvidia,tegra20-i2c-dvc" ),COMPAT (NVIDIA_TEGRA20_EMC ,"nvidia,tegra20-emc" ),COMPAT (NVIDIA_TEGRA20_EMC_TABLE ,"nvidia,tegra20-emc-table" ), + COMPAT(NVIDIA_TEGRA20_NAND, "nvidia,tegra20-nand"), };const char *fdtdec_get_compatible (enum fdt_compat_id id)
Signature · 1 line
1.7.7.3
PATCH 5/6 tegra: nand: Add Tegra NAND driver
Quoted 9 lines · On Friday 13 January 2012 18:10:55 Simon Glass wrote:
From: Jim Lin <[email protected]>
A device tree is used to configure the NAND, including memory timings and block/pages sizes.
If this node is not present or is disabled, then NAND will not be initialized.
Signed-off-by Simon Glass <[email protected]>
the Author needs to sign off too ...
-mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20120114/14670706/attachment.pgp>
PATCH 5/6 tegra: nand: Add Tegra NAND driver
Hi Mike,
Quoted 6 lines · Mike Frysinger
Quoted 5 lines · On Friday 13 January 2012 18:10:55 Simon Glass wrote:
From: Jim Lin <[email protected]>
A device tree is used to configure the NAND, including memory timings and block/pages sizes.
Quoted 6 lines
Quoted 4 lines
If this node is not present or is disabled, then NAND will not be initialized.
Signed-off-by Simon Glass <[email protected]>the Author needs to sign off too ...
I have a lot like that. It doesn't feel right for me to just add their sign-off after all my changes. I was hoping that they would reply to the list with it. Does that work? The original commit does not have a sign-off.
Regards,
Simon
Quoted 1 line
-mike
PATCH 5/6 tegra: nand: Add Tegra NAND driver
Quoted 10 lines · On Saturday 14 January 2012 23:08:45 Simon Glass wrote:
Quoted 9 lines · Mike Frysinger
Quoted 8 lines · On Friday 13 January 2012 18:10:55 Simon Glass wrote:
From: Jim Lin <[email protected]>
A device tree is used to configure the NAND, including memory timings and block/pages sizes.
If this node is not present or is disabled, then NAND will not be initialized.
Quoted 8 lines
Quoted 3 lines
Quoted 1 line
Signed-off-by Simon Glass <[email protected]>the Author needs to sign off too ...
I have a lot like that. It doesn't feel right for me to just add their sign-off after all my changes. I was hoping that they would reply to the list with it. Does that work? The original commit does not have a sign-off.
sure, if the author replies with their s-o-b, or says they're OK with you adding it, that's fine. but you're right that you can't just add it yourself without them saying so first ...
-mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20120114/8c114ff7/attachment.pgp>
PATCH 5/6 tegra: nand: Add Tegra NAND driver
Simon,
Could you also add
for me?
Thanks,
Jim
-----Original Message-----
From: Mike Frysinger [mailto:vapier at gentoo.org]
Sent: Sunday, January 15, 2012 12:12 PM
To: Simon Glass
Cc: u-boot at lists.denx.de; Jim Lin; Tom Warren; Scott Wood
Subject: Re: [U-Boot] [PATCH 5/6] tegra: nand: Add Tegra NAND driver
* PGP Signed by an unknown key
Quoted 10 lines · On Saturday 14 January 2012 23:08:45 Simon Glass wrote:
Quoted 9 lines · Mike Frysinger
Quoted 8 lines · On Friday 13 January 2012 18:10:55 Simon Glass wrote:
From: Jim Lin <[email protected]>
A device tree is used to configure the NAND, including memory timings and block/pages sizes.
If this node is not present or is disabled, then NAND will not be initialized.
Quoted 8 lines
Quoted 3 lines
Quoted 1 line
Signed-off-by Simon Glass <[email protected]>the Author needs to sign off too ...
I have a lot like that. It doesn't feel right for me to just add their sign-off after all my changes. I was hoping that they would reply to the list with it. Does that work? The original commit does not have a sign-off.
sure, if the author replies with their s-o-b, or says they're OK with you adding it, that's fine. but you're right that you can't just add it yourself without them saying so first ...
-mike
* Unknown Key
* 0xE837F581
-----------------------------------------------------------------------------------
This email message is for the sole use of the intended recipient(s) and may contain confidential information. Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply email and destroy all copies of the original message.
-----------------------------------------------------------------------------------
PATCH 5/6 tegra: nand: Add Tegra NAND driver
In reply to Simon GlassQuoted 40 lines · Simon Glass
From: Jim Lin <[email protected]>
A device tree is used to configure the NAND, including memory timings and block/pages sizes.
If this node is not present or is disabled, then NAND will not be initialized.
Signed-off-by Simon Glass <[email protected]>drivers/mtd/nand/tegra2_nand.c +28
-0+/** +* Wait for command completion +* +* @param reg nand_ctlr structure +* @return +* 1 - Command completed +* 0 - Timeout +*/ +static int nand_waitfor_cmd_completion (struct nand_ctlr *reg) +{ +int i; +u32 reg_val; + +for (i =0 ; i <NAND_CMD_TIMEOUT_MS *1000 ; i++) { +if ((readl (®->command) &CMD_GO ) || + !(readl (®->status) & +STATUS_RBSY0 ) || + !(readl (®->isr) & +ISR_IS_CMD_DONE )) { +udelay (1 ); +continue ; + } + reg_val =readl (®->dma_mst_ctrl); +/* +* If DMA_MST_CTRL_EN_A_ENABLE or +* DMA_MST_CTRL_EN_B_ENABLE is set, +* that means DMA engine is running, then we +* have to wait until
drivers/mtd/nand/tegra2_nand.c line 147
Quoted 10 lines
drivers/mtd/nand/tegra2_nand.c +10
-0+* DMA_MST_CTRL_IS_DMA_DONE +* is cleared for DMA transfer completion. +*/ +if (reg_val & (DMA_MST_CTRL_EN_A_ENABLE | +DMA_MST_CTRL_EN_B_ENABLE )) { +if (reg_val &DMA_MST_CTRL_IS_DMA_DONE ) +return 1 ; + }else +return 1 ; +udelay (1 );
To be more consistent with the first if/continue block, wouldn't it be better to recast that last if test and udelay as:
if (reg_val & (DMA_MST_CTRL_EN_A_ENABLE |
DMA_MST_CTRL_EN_B_ENABLE)) {
if (!(reg_val & DMA_MST_CTRL_IS_DMA_DONE)) {
udelay(1);
continue;
}
}
break;Quoted 17 lines
drivers/mtd/nand/tegra2_nand.c +17
-0+/** +* [DEFAULT] Send command to NAND device +* +* @param mtd MTD device structure +* @param command the command to be sent +* @param column the column address for this command, -1 if none +* @param page_addr the page address for this command, -1 if none +*/ +static void nand_command (struct mtd_info *mtd,unsigned int command, +int column,int page_addr) +{ + registerstruct nand_chip *chip = mtd->priv; +struct nand_info *info; + + info = (struct nand_info *) chip->priv; + +/*
drivers/mtd/nand/tegra2_nand.c line 330
Quoted 10 lines
drivers/mtd/nand/tegra2_nand.c +10
-0+* Write out the command to the device. +*/ +if (mtd->writesize <2048 ) { +/* +* Only command NAND_CMD_RESET or NAND_CMD_READID will come +* here before mtd->writesize is initialized, we don't have +* any action here because page size of NAND HY27UF084G2B +* is 2048 bytes and mtd->writesize will be 2048 after +* initialized. +*/
What if the NAND flash doesn't have a page size of 2048 bytes? The driver shouldn't make such assumptions about the flash chip that happens to be connected. Should the if above be:
if (mtd->writesize == 0)
to be generic?
Should this if branch validate that the command being executed is a legitimate command for the not-yet-fully-initialized case?
drivers/mtd/nand/tegra2_nand.c line 528
Quoted 13 lines
drivers/mtd/nand/tegra2_nand.c +13
-0+/** +* Set up NAND bus width and page size +* +* @param info nand_info structure +* @param *reg_val address of reg_val +* @return none - value is set in reg_val +*/ +static void set_bus_width_page_size (struct fdt_nand *config, +u32 *reg_val) +{ +if (config->width ==8 ) + *reg_val =CFG_BUS_WIDTH_8BIT ; +else
Shouldn't that be else if (config->width == 16)
Quoted 1 line
+
*reg_val=CFG_BUS_WIDTH_16BIT;
... and there be an else clause that returns an error?
drivers/mtd/nand/tegra2_nand.c line 538
Quoted 9 lines
drivers/mtd/nand/tegra2_nand.c +9
-0+ +if (config->page_data_bytes ==256 ) + *reg_val |=CFG_PAGE_SIZE_256 ; +else if (config->page_data_bytes ==512 ) + *reg_val |=CFG_PAGE_SIZE_512 ; +else if (config->page_data_bytes ==1024 ) + *reg_val |=CFG_PAGE_SIZE_1024 ; +else if (config->page_data_bytes ==2048 ) + *reg_val |=CFG_PAGE_SIZE_2048 ;
And similarly, and else clause that returns an error here?
Signature · 1 line
nvpublic
PATCH 5/6 tegra: nand: Add Tegra NAND driver
Hi Stephen,
Quoted 64 lines · Stephen Warren
Quoted 40 lines · Simon Glass
From: Jim Lin <[email protected]>
A device tree is used to configure the NAND, including memory timings and block/pages sizes.
If this node is not present or is disabled, then NAND will not be initialized.
Signed-off-by Simon Glass <[email protected]>drivers/mtd/nand/tegra2_nand.c +28
-0+/** +* Wait for command completion +* +* @param reg ?nand_ctlr structure +* @return +* ? ? 1 - Command completed +* ? ? 0 - Timeout +*/ +static int nand_waitfor_cmd_completion (struct nand_ctlr *reg) +{ + ? ? ? int i; + ? ? ? u32 reg_val; + + ? ? ? for (i = 0; i < NAND_CMD_TIMEOUT_MS * 1000; i++) { + ? ? ? ? ? ? ? if ((readl(®->command) & CMD_GO) || + ? ? ? ? ? ? ? ? ? ? ? !(readl(®->status) & + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? STATUS_RBSY0) || + ? ? ? ? ? ? ? ? ? ? ? !(readl(®->isr) & + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ISR_IS_CMD_DONE)) { + ? ? ? ? ? ? ? ? ? ? ? udelay(1); + ? ? ? ? ? ? ? ? ? ? ? continue; + ? ? ? ? ? ? ? } + ? ? ? ? ? ? ? reg_val = readl(®->dma_mst_ctrl); + ? ? ? ? ? ? ? /* +? ? ? ? ? ? ? ?* If DMA_MST_CTRL_EN_A_ENABLE or +? ? ? ? ? ? ? ?* DMA_MST_CTRL_EN_B_ENABLE is set, +? ? ? ? ? ? ? ?* that means DMA engine is running, then we +? ? ? ? ? ? ? ?* have to wait until drivers/mtd/nand/tegra2_nand.c
Quoted 10 lines
drivers/mtd/nand/tegra2_nand.c +10
-0+? ? ? ? ? ? ? ?* DMA_MST_CTRL_IS_DMA_DONE +? ? ? ? ? ? ? ?* is cleared for DMA transfer completion. +? ? ? ? ? ? ? ?*/ + ? ? ? ? ? ? ? if (reg_val & (DMA_MST_CTRL_EN_A_ENABLE | + ? ? ? ? ? ? ? ? ? ? ? DMA_MST_CTRL_EN_B_ENABLE)) { + ? ? ? ? ? ? ? ? ? ? ? if (reg_val & DMA_MST_CTRL_IS_DMA_DONE) + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? return 1; + ? ? ? ? ? ? ? } else + ? ? ? ? ? ? ? ? ? ? ? return 1; + ? ? ? ? ? ? ? udelay(1);To be more consistent with the first if/continue block, wouldn't it be better to recast that last if test and udelay as:
? ? ? ? ? ? ? if (
reg_val& (DMA_MST_CTRL_EN_A_ENABLE| ? ? ? ? ? ? ? ? ? ? ?DMA_MST_CTRL_EN_B_ENABLE)) {
? ? ? ? ? ? ? ? ? ? ? if (!(reg_val &DMA_MST_CTRL_IS_DMA_DONE)) { ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? udelay(1);
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? continue;
? ? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? }
Quoted 1 line
? ? ? ? ? ? ? break;
Yes that is better - but I've split it up a bit as it is too ugly. Also I do want to actually make use of the udelay that is there, rather than breaking out of the loop by default.
Quoted 34 lines
Quoted 19 lines
drivers/mtd/nand/tegra2_nand.c +17
-0+/** +* [DEFAULT] Send command to NAND device +* +* @param mtd ? ? ? ? ?MTD device structure +* @param command ? ? ?the command to be sent +* @param column ? ? ? the column address for this command, -1 if none +* @param page_addr ? ?the page address for this command, -1 if none +*/ +static void nand_command (struct mtd_info *mtd,unsigned int command, + ? ? ? int column, int page_addr) +{ + ? ? ? register struct nand_chip *chip = mtd->priv; + ? ? ? struct nand_info *info; + + ? ? ? info = (struct nand_info *) chip->priv; + + ? ? ? /*drivers/mtd/nand/tegra2_nand.c
Quoted 10 lines
drivers/mtd/nand/tegra2_nand.c +10
-0+? ? ? ?* Write out the command to the device. +? ? ? ?*/ + ? ? ? if (mtd->writesize < 2048) { + ? ? ? ? ? ? ? /* +? ? ? ? ? ? ? ?* Only command NAND_CMD_RESET or NAND_CMD_READID will come +? ? ? ? ? ? ? ?* here before mtd->writesize is initialized, we don't have +? ? ? ? ? ? ? ?* any action here because page size of NAND HY27UF084G2B +? ? ? ? ? ? ? ?* is 2048 bytes and mtd->writesize will be 2048 after +? ? ? ? ? ? ? ?* initialized. +? ? ? ? ? ? ? ?*/ What if the NAND flash doesn't have a page size of 2048 bytes? The driver shouldn't make such assumptions about the flash chip that happens to be connected. Should the if above be:
Quoted 3 lines
? ?if (
mtd->writesize== 0)to be generic?
Well I have just removed this, as Scott suggested.
Quoted 3 lines
Should this if branch validate that the command being executed is a legitimate command for the not-yet-fully-initialized case?
Removed
Quoted 17 lines
Quoted 4 lines
drivers/mtd/nand/tegra2_nand.c +3
-0+/** +* Set up NAND bus width and page size +* drivers/mtd/nand/tegra2_nand.c
Quoted 10 lines
drivers/mtd/nand/tegra2_nand.c +10
-0+* @param info ? ? ? ? nand_info structure +* @param *reg_val ? ? address of reg_val +* @return none - value is set in reg_val +*/ +static void set_bus_width_page_size (struct fdt_nand *config, + ? ? ? u32 *reg_val) +{ + ? ? ? if (config->width == 8) + ? ? ? ? ? ? ? *reg_val = CFG_BUS_WIDTH_8BIT; + ? ? ? elseShouldn't that be else if (
config->width== 16)
Quoted 4 lines
Quoted 1 line
+ ? ? ? ? ? ? ?
*reg_val=CFG_BUS_WIDTH_16BIT;... and there be an else clause that returns an error?
Done, have also called it from init as Scott suggests.
Quoted 11 lines
Quoted 10 lines
+
+ ? ? ? if (config->page_data_bytes== 256)
+ ? ? ? ? ? ? ?*reg_val|=CFG_PAGE_SIZE_256;
+ ? ? ? else if (config->page_data_bytes== 512)
+ ? ? ? ? ? ? ?*reg_val|=CFG_PAGE_SIZE_512;
+ ? ? ? else if (config->page_data_bytes== 1024)
+ ? ? ? ? ? ? ?*reg_val|=CFG_PAGE_SIZE_1024;
+ ? ? ? else if (config->page_data_bytes== 2048)
+ ? ? ? ? ? ? ?*reg_val|=CFG_PAGE_SIZE_2048;
Quoted 1 line
And similarly, and else clause that returns an error here?
Done
Quoted 3 lines
--
nvpublic
Regards,
Simon
PATCH 5/6 tegra: nand: Add Tegra NAND driver
In reply to Simon GlassQuoted 8 lines · Simon Glass
drivers/mtd/nand/tegra2_nand.c new file +8
-0+/* Information about an attached NAND chip */ +struct fdt_nand { +struct nand_ctlr *reg; +int enabled;/* 1 to enable, 0 to disable */ +struct fdt_gpio_state wp_gpio;/* write-protect GPIO */ +int width;/* bit width, normally 8 */ +int tag_ecc_bytes;/* ECC bytes to be generated for tag bytes */ +int tag_bytes;/* Tag bytes in spare area */
drivers/mtd/nand/tegra2_nand.c line 90
Quoted 10 lines
drivers/mtd/nand/tegra2_nand.c new file +10
-0+int data_ecc_bytes;/* ECC bytes for data area */ +int skipped_spare_bytes; +/* +* How many bytes in spare area: +* spare area = skipped bytes + ECC bytes of data area +* + tag bytes + ECC bytes of tag bytes +*/ +int page_spare_bytes; +int page_data_bytes;/* Bytes in data area */ +unsigned timing[FDT_NAND_TIMING_COUNT ];
s/unsigned/u32/g
Likewise, any of these other fields that correspond to device tree fields should be u32 or s32.
...and even when you do mean "unsigned int", please spell it out.
Quoted 1 line
+struct
nand_info{
Please do not define "struct nand_info" when there is already a different "nand_info_t".
Quoted 1 line
+struct
nand_infonand_ctrl;
static (or better, dynamic).
Quoted 25 lines
drivers/mtd/nand/tegra2_nand.c new file +25
-0+/** +* Wait for command completion +* +* @param reg nand_ctlr structure +* @return +* 1 - Command completed +* 0 - Timeout +*/ +static int nand_waitfor_cmd_completion (struct nand_ctlr *reg) +{ +int i; +u32 reg_val; + +for (i =0 ; i <NAND_CMD_TIMEOUT_MS *1000 ; i++) { +if ((readl (®->command) &CMD_GO ) || + !(readl (®->status) & +STATUS_RBSY0 ) || + !(readl (®->isr) & +ISR_IS_CMD_DONE )) { +udelay (1 ); +continue ; + } + reg_val =readl (®->dma_mst_ctrl); +/* +* If DMA_MST_CTRL_EN_A_ENABLE or
drivers/mtd/nand/tegra2_nand.c line 144
Quoted 10 lines
drivers/mtd/nand/tegra2_nand.c new file +10
-0+* DMA_MST_CTRL_EN_B_ENABLE is set, +* that means DMA engine is running, then we +* have to wait until +* DMA_MST_CTRL_IS_DMA_DONE +* is cleared for DMA transfer completion. +*/ +if (reg_val & (DMA_MST_CTRL_EN_A_ENABLE | +DMA_MST_CTRL_EN_B_ENABLE )) { +if (reg_val &DMA_MST_CTRL_IS_DMA_DONE ) +return 1 ;
Please don't line up continuation lines with the if-body.
E.g. either line up DMA_MST_CTRL_EN_B_ENABLE with DMA_MST_CTRL_EN_A_ENABLE (my preference), or just add another tab (if you want to be a tabs-only purist).
drivers/mtd/nand/tegra2_nand.c line 146
Quoted 2 lines
drivers/mtd/nand/tegra2_nand.c new file +2
-0+ }else +return 1 ;
If braces are used on one side of the if/else, use on both sides.
Quoted 7 lines
drivers/mtd/nand/tegra2_nand.c new file +7
-0+udelay (1 ); + } +return 0 ; +} + +/** +* [DEFAULT] Read one byte from the chip
drivers/mtd/nand/tegra2_nand.c line 163
Quoted 10 lines
drivers/mtd/nand/tegra2_nand.c new file +10
-0+* +* @param mtd MTD device structure +* @return data byte +* +* Default read function for 8bit bus-width +*/ +static uint8_t read_byte (struct mtd_info *mtd) +{ +struct nand_chip *chip = mtd->priv; +int dword_read;
s/int/u32/
drivers/mtd/nand/tegra2_nand.c line 171
Quoted 8 lines
drivers/mtd/nand/tegra2_nand.c new file +8
-0+struct nand_info *info; + + info = (struct nand_info *) chip->priv; + + dword_read =readl (&info->reg->resp); + dword_read = dword_read >> (8 * info->pio_byte_index); + info->pio_byte_index++; +return (uint8_t ) dword_read;
No space after casts.
What happens when pio_byte_index > 3? Please don't assume that upper bits will be ignored, even if that happens to be true on this chip.
How does info->reg->resp work? You don't seem to be choosing the dword to read based on pio_byte_index, which suggests that the act of reading resp changes what will be read the next time. But, you read it on each byte, which would advance resp four times too fast if it's simply returning a new dword each time.
If the hardware is really auto-advancing resp only on every fourth access, that needs a comment.
drivers/mtd/nand/tegra2_nand.c line 288
Quoted 5 lines
drivers/mtd/nand/tegra2_nand.c new file +5
-0+/* Hardware specific access to control-lines */ +static void nand_hwcontrol (struct mtd_info *mtd,int cmd, +unsigned int ctrl) +{ +}
Don't implement this at all if it doesn't make sense for this hardware.
Quoted 17 lines
drivers/mtd/nand/tegra2_nand.c new file +17
-0+ +/** +* Clear all interrupt status bits +* +* @param reg nand_ctlr structure +*/ +static void nand_clear_interrupt_status (struct nand_ctlr *reg) +{ +u32 reg_val; + +/* Clear interrupt status */ + reg_val =readl (®->isr); +writel (reg_val, ®->isr); +} + +/** +* [DEFAULT] Send command to NAND device
drivers/mtd/nand/tegra2_nand.c line 315
Quoted 10 lines
drivers/mtd/nand/tegra2_nand.c new file +10
-0+* +* @param mtd MTD device structure +* @param command the command to be sent +* @param column the column address for this command, -1 if none +* @param page_addr the page address for this command, -1 if none +*/ +static void nand_command (struct mtd_info *mtd,unsigned int command, +int column,int page_addr) +{ + registerstruct nand_chip *chip = mtd->priv;
Are you really seeing any difference by using the register keyword?
Quoted 5 lines
drivers/mtd/nand/tegra2_nand.c new file +5
-0+struct nand_info *info; + + info = (struct nand_info *) chip->priv; + +/*
drivers/mtd/nand/tegra2_nand.c line 330
Quoted 10 lines
drivers/mtd/nand/tegra2_nand.c new file +10
-0+* Write out the command to the device. +*/ +if (mtd->writesize <2048 ) { +/* +* Only command NAND_CMD_RESET or NAND_CMD_READID will come +* here before mtd->writesize is initialized, we don't have +* any action here because page size of NAND HY27UF084G2B +* is 2048 bytes and mtd->writesize will be 2048 after +* initialized. +*/
Why are you assuming a particular NAND chip here?
If you want to not support certain page sizes in this driver, fine, but document that somewhere more prominent, and I don't see why this test is needed.
drivers/mtd/nand/tegra2_nand.c line 341
Quoted 11 lines
drivers/mtd/nand/tegra2_nand.c new file +11
-0+ }else { +/* Emulate NAND_CMD_READOOB */ +if (command ==NAND_CMD_READOOB ) { + column += mtd->writesize; + command =NAND_CMD_READ0 ; + } + +/* Adjust columns for 16 bit bus-width */ +if (column !=-1 && (chip->options &NAND_BUSWIDTH_16 )) + column >>=1 ; + }
Why does the treatment of column for NAND_CMD_READID depend on whether you've yet filled in mtd->writesize?
Quoted 12 lines
drivers/mtd/nand/tegra2_nand.c new file +12
-0+nand_clear_interrupt_status (info->reg); + +/* Stop DMA engine, clear DMA completion status */ +writel (DMA_MST_CTRL_EN_A_DISABLE + |DMA_MST_CTRL_EN_B_DISABLE + |DMA_MST_CTRL_IS_DMA_DONE , + &info->reg->dma_mst_ctrl); + +/* +* Program and erase have their own busy handlers +* status and sequential in needs no delay +*/
drivers/mtd/nand/tegra2_nand.c line 364
Quoted 10 lines
drivers/mtd/nand/tegra2_nand.c new file +10
-0+switch (command) { +case NAND_CMD_READID : +writel (NAND_CMD_READID , &info->reg->cmd_reg1); +writel (CMD_GO |CMD_CLE |CMD_ALE |CMD_PIO + |CMD_RX | + (CMD_TRANS_SIZE_BYTES4 <<CMD_TRANS_SIZE_SHIFT ) + |CMD_CE0 , + &info->reg->command); + info->pio_byte_index =0 ; +break ;
Looks like you don't use column at all for READID -- no ONFI support, I guess.
Quoted 17 lines
drivers/mtd/nand/tegra2_nand.c new file +17
-0+case NAND_CMD_READ0 : +writel (NAND_CMD_READ0 , &info->reg->cmd_reg1); +writel (NAND_CMD_READSTART , &info->reg->cmd_reg2); +writel ((page_addr <<16 ) | (column &0xFFFF ), + &info->reg->addr_reg1); +writel (page_addr >>16 , &info->reg->addr_reg2); +return ; +case NAND_CMD_SEQIN : +writel (NAND_CMD_SEQIN , &info->reg->cmd_reg1); +writel (NAND_CMD_PAGEPROG , &info->reg->cmd_reg2); +writel ((page_addr <<16 ) | (column &0xFFFF ), + &info->reg->addr_reg1); +writel (page_addr >>16 , + &info->reg->addr_reg2); +return ; +case NAND_CMD_PAGEPROG : +return ;
drivers/mtd/nand/tegra2_nand.c line 391
Quoted 10 lines
drivers/mtd/nand/tegra2_nand.c new file +10
-0+case NAND_CMD_ERASE1 : +writel (NAND_CMD_ERASE1 , &info->reg->cmd_reg1); +writel (NAND_CMD_ERASE2 , &info->reg->cmd_reg2); +writel (page_addr, &info->reg->addr_reg1); +writel (CMD_GO |CMD_CLE |CMD_ALE | +CMD_SEC_CMD |CMD_CE0 |CMD_ALE_BYTES3 , + &info->reg->command); +break ; +case NAND_CMD_RNDOUT : +return ;
Don't silently ignore RNDOUT -- if you don't support it and it happens, complain loudly.
Quoted 8 lines
drivers/mtd/nand/tegra2_nand.c new file +8
-0+case NAND_CMD_ERASE2 : +return ; +case NAND_CMD_STATUS : +writel (NAND_CMD_STATUS , &info->reg->cmd_reg1); + writel(CMD_GO | CMD_CLE | CMD_PIO | CMD_RX + | (CMD_TRANS_SIZE_BYTES1 << + CMD_TRANS_SIZE_SHIFT) + | CMD_CE0,
drivers/mtd/nand/tegra2_nand.c line 409
Quoted 10 lines
drivers/mtd/nand/tegra2_nand.c new file +10
-0+ &info->reg->command); + info->pio_byte_index =0 ; +break ; +case NAND_CMD_RESET : +writel (NAND_CMD_RESET , &info->reg->cmd_reg1); +writel (CMD_GO |CMD_CLE |CMD_CE0 , + &info->reg->command); +break ; +default : +return ;
Likewise, complain if you get an unrecognized command.
Quoted 13 lines
drivers/mtd/nand/tegra2_nand.c new file +13
-0+/** +* Set up NAND bus width and page size +* +* @param info nand_info structure +* @param *reg_val address of reg_val +* @return none - value is set in reg_val +*/ +static void set_bus_width_page_size (struct fdt_nand *config, +u32 *reg_val) +{ +if (config->width ==8 ) + *reg_val =CFG_BUS_WIDTH_8BIT ; +else
drivers/mtd/nand/tegra2_nand.c line 538
Quoted 10 lines
drivers/mtd/nand/tegra2_nand.c new file +10
-0+ *reg_val =CFG_BUS_WIDTH_16BIT ; + +if (config->page_data_bytes ==256 ) + *reg_val |=CFG_PAGE_SIZE_256 ; +else if (config->page_data_bytes ==512 ) + *reg_val |=CFG_PAGE_SIZE_512 ; +else if (config->page_data_bytes ==1024 ) + *reg_val |=CFG_PAGE_SIZE_1024 ; +else if (config->page_data_bytes ==2048 ) + *reg_val |=CFG_PAGE_SIZE_2048 ;
Really, page sizes of 256 and 1024 bytes?
PATCH 5/6 tegra: nand: Add Tegra NAND driver
Hi Scott,
Quoted 13 lines · Scott Wood
Quoted 12 lines · Simon Glass
(quoted diff) +12
-0+/* Information about an attached NAND chip */ +struct fdt_nand { + ? ? struct nand_ctlr *reg; + ? ? int enabled; ? ? ? ? ? ?/* 1 to enable, 0 to disable */ + ? ? struct fdt_gpio_state wp_gpio; ?/* write-protect GPIO */ + ? ? int width; ? ? ? ? ? ? ?/* bit width, normally 8 */ + ? ? int tag_ecc_bytes; ? ? ?/* ECC bytes to be generated for tag bytes */ + ? ? int tag_bytes; ? ? ? ? ?/* Tag bytes in spare area */ + ? ? int data_ecc_bytes; ? ? /* ECC bytes for data area */ + ? ? int skipped_spare_bytes; + ? ? /* + ? ? ?* How many bytes in spare area:
Quoted 8 lines
Quoted 6 lines
+ ? ? ?* spare area = skipped bytes + ECC bytes of data area
+ ? ? ?* + tag bytes + ECC bytes of tag bytes
+ ? ? ?*/
+ ? ? intpage_spare_bytes;
+ ? ? intpage_data_bytes; ? ?/* Bytes in data area */
+ ? ? unsigned timing[FDT_NAND_TIMING_COUNT];s/unsigned/u32/g
Done
Quoted 3 lines
Likewise, any of these other fields that correspond to device tree fields should be u32 or s32.
Done
Quoted 7 lines
...and even when you do mean "unsigned int", please spell it out.
Quoted 1 line
+struct
nand_info{Please do not define "struct
nand_info" when there is already a different "nand_info_t".
Done
Quoted 4 lines
Quoted 2 lines
+struct
nand_infonand_ctrl;static (or better, dynamic).
Done, what is dynamic?
Quoted 39 lines
Quoted 26 lines
(quoted diff) +25
-0+/** + * Wait for command completion + * + * @param reg ? ? ? ?nand_ctlr structure + * @return + * ? 1 - Command completed + * ? 0 - Timeout + */ +static int nand_waitfor_cmd_completion(struct nand_ctlr *reg) +{ + ? ? int i; + ? ? u32 reg_val; + + ? ? for (i = 0; i < NAND_CMD_TIMEOUT_MS * 1000; i++) { + ? ? ? ? ? ? if ((readl(®->command) & CMD_GO) || + ? ? ? ? ? ? ? ? ? ? !(readl(®->status) & + ? ? ? ? ? ? ? ? ? ? ? ? ? ? STATUS_RBSY0) || + ? ? ? ? ? ? ? ? ? ? !(readl(®->isr) & + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ISR_IS_CMD_DONE)) { + ? ? ? ? ? ? ? ? ? ? udelay(1); + ? ? ? ? ? ? ? ? ? ? continue; + ? ? ? ? ? ? } + ? ? ? ? ? ? reg_val = readl(®->dma_mst_ctrl); + ? ? ? ? ? ? /* + ? ? ? ? ? ? ?* If DMA_MST_CTRL_EN_A_ENABLE orReview
Quoted 10 lines
(quoted diff) +10
-0+ ? ? ? ? ? ? ?* DMA_MST_CTRL_EN_B_ENABLE is set, + ? ? ? ? ? ? ?* that means DMA engine is running, then we + ? ? ? ? ? ? ?* have to wait until + ? ? ? ? ? ? ?* DMA_MST_CTRL_IS_DMA_DONE + ? ? ? ? ? ? ?* is cleared for DMA transfer completion. + ? ? ? ? ? ? ?*/ + ? ? ? ? ? ? if (reg_val & (DMA_MST_CTRL_EN_A_ENABLE | + ? ? ? ? ? ? ? ? ? ? DMA_MST_CTRL_EN_B_ENABLE)) { + ? ? ? ? ? ? ? ? ? ? if (reg_val & DMA_MST_CTRL_IS_DMA_DONE) + ? ? ? ? ? ? ? ? ? ? ? ? ? ? return 1;Please don't line up continuation lines with the if-body.
Quoted 3 lines
E.g. either line up
DMA_MST_CTRL_EN_B_ENABLEwithDMA_MST_CTRL_EN_A_ENABLE(my preference), or just add another tab (if you want to be a tabs-only purist).
Yes, ick, have fixed that.
Quoted 5 lines
Quoted 3 lines
+ ? ? ? ? ? ? } else
+ ? ? ? ? ? ? ? ? ? ? return 1;If braces are used on one side of the if/else, use on both sides.
Done
Quoted 12 lines
Quoted 12 lines
+ ? ? ? ? ? ? udelay(1);
+ ? ? }
+ ? ? return 0;drivers/mtd/nand/tegra2_nand.c new file +8
-0+} + +/** +* [DEFAULT] Read one byte from the chip +* +* @param mtd ? ? ? ?MTD device structure +* @return ? data byte +*
Quoted 8 lines
drivers/mtd/nand/tegra2_nand.c
Quoted 6 lines
+ * Default read function for 8bit bus-width
+ */drivers/mtd/nand/tegra2_nand.c new file +4
-0+static uint8_t read_byte (struct mtd_info *mtd) +{ + ? ? struct nand_chip *chip = mtd->priv; + ? ? int dword_read;s/int/u32/
done
Quoted 11 lines
Review
Quoted 9 lines
+ ? ? struct
nand_info*info;(quoted diff) +7
-0+ + ? ? info = (struct nand_info *) chip->priv; + + ? ? dword_read = readl(&info->reg->resp); + ? ? dword_read = dword_read >> (8 * info->pio_byte_index); + ? ? info->pio_byte_index++; + ? ? return (uint8_t) dword_read;No space after casts.
I think I have fixed that globally.
Quoted 3 lines
What happens when
pio_byte_index> 3? ?Please don't assume that upper bits will be ignored, even if that happens to be true on this chip.
I added an assert() - there is no way to return an error here. I'm not sure what you mean by upper bits - there is a uint8_t cast.
Quoted 9 lines
How does
info->reg->respwork? ?You don't seem to be choosing the dword to read based onpio_byte_index, which suggests that the act of reading resp changes what will be read the next time. ?But, you read it on each byte, which would advance resp four times too fast if it's simply returning a new dword each time.If the hardware is really auto-advancing resp only on every fourth access, that needs a comment.
I was just looking at that. Have added a comment.
Quoted 8 lines
drivers/mtd/nand/tegra2_nand.c line 288
Quoted 6 lines
drivers/mtd/nand/tegra2_nand.c new file +5
-0+/* Hardware specific access to control-lines */ +static void nand_hwcontrol (struct mtd_info *mtd,int cmd, + ? ? unsigned int ctrl) +{ +}Don't implement this at all if it doesn't make sense for this hardware.
It isn't implemented (the function is empty), but if it is not defined then the NAND layer will die when it calls a null function. What should I do here?
Quoted 22 lines
Quoted 22 lines
drivers/mtd/nand/tegra2_nand.c new file +21
-0+ +/** +* Clear all interrupt status bits +* +* @param reg ? ? ? ?nand_ctlr structure +*/ +static void nand_clear_interrupt_status (struct nand_ctlr *reg) +{ + ? ? u32 reg_val; + + ? ? /* Clear interrupt status */ + ? ? reg_val = readl(®->isr); + ? ? writel(reg_val, ®->isr); +} + +/** +* [DEFAULT] Send command to NAND device +* +* @param mtd ? ? ? ? ? ? ? ?MTD device structure +* @param command ? ?the command to be sent +* @param column ? ? the column address for this command, -1 if none
Quoted 8 lines
drivers/mtd/nand/tegra2_nand.c
Quoted 6 lines
+ * @param
page_addr?the page address for this command, -1 if none
+ */drivers/mtd/nand/tegra2_nand.c new file +4
-0+static void nand_command (struct mtd_info *mtd,unsigned int command, + ? ? int column, int page_addr) +{ + ? ? register struct nand_chip *chip = mtd->priv;Are you really seeing any difference by using the register keyword?
I doubt it, will remove globally.
Quoted 19 lines
Quoted 6 lines
+ ? ? struct
nand_info*info;(quoted diff) +4
-0+ + ? ? info = (struct nand_info *) chip->priv; + + ? ? /*Review
Quoted 10 lines
(quoted diff) +10
-0+ ? ? ?* Write out the command to the device. + ? ? ?*/ + ? ? if (mtd->writesize < 2048) { + ? ? ? ? ? ? /* + ? ? ? ? ? ? ?* Only command NAND_CMD_RESET or NAND_CMD_READID will come + ? ? ? ? ? ? ?* here before mtd->writesize is initialized, we don't have + ? ? ? ? ? ? ?* any action here because page size of NAND HY27UF084G2B + ? ? ? ? ? ? ?* is 2048 bytes and mtd->writesize will be 2048 after + ? ? ? ? ? ? ?* initialized. + ? ? ? ? ? ? ?*/Why are you assuming a particular NAND chip here?
Quoted 3 lines
If you want to not support certain page sizes in this driver, fine, but document that somewhere more prominent, and I don't see why this test is needed.
Yes I agree, will punt it.
Quoted 13 lines
Quoted 12 lines
+ ? ? } else {
+ ? ? ? ? ? ? /* EmulateNAND_CMD_READOOB*/
+ ? ? ? ? ? ? if (command ==NAND_CMD_READOOB) {
+ ? ? ? ? ? ? ? ? ? ? column +=mtd->writesize;
+ ? ? ? ? ? ? ? ? ? ? command =NAND_CMD_READ0;
+ ? ? ? ? ? ? }
+
+ ? ? ? ? ? ? /* Adjust columns for 16 bit bus-width */
+ ? ? ? ? ? ? if (column != -1 && (chip->options&NAND_BUSWIDTH_16))
+ ? ? ? ? ? ? ? ? ? ? column >>= 1;
+ ? ? }
Quoted 2 lines
Why does the treatment of column for
NAND_CMD_READIDdepend on whether you've yet filled inmtd->writesize?
Not sure, punted.
Quoted 18 lines
Quoted 18 lines
+ ? ?
nand_clear_interrupt_status(info->reg);(quoted diff) +16
-0+ + ? ? /* Stop DMA engine, clear DMA completion status */ + ? ? writel(DMA_MST_CTRL_EN_A_DISABLE + ? ? ? ? ? ? | DMA_MST_CTRL_EN_B_DISABLE + ? ? ? ? ? ? | DMA_MST_CTRL_IS_DMA_DONE, + ? ? ? ? ? ? &info->reg->dma_mst_ctrl); + + ? ? /* + ? ? ?* Program and erase have their own busy handlers + ? ? ?* status and sequential in needs no delay + ? ? ?*/ + ? ? switch (command) { + ? ? case NAND_CMD_READID: + ? ? ? ? ? ? writel(NAND_CMD_READID, &info->reg->cmd_reg1); + ? ? ? ? ? ? writel(CMD_GO | CMD_CLE | CMD_ALE | CMD_PIO + ? ? ? ? ? ? ? ? ? ? | CMD_RX |
Quoted 8 lines
Quoted 5 lines
+ ? ? ? ? ? ? ? ? ? ? (
CMD_TRANS_SIZE_BYTES4<<CMD_TRANS_SIZE_SHIFT)
+ ? ? ? ? ? ? ? ? ? ? |CMD_CE0,
+ ? ? ? ? ? ? ? ? ? ?&info->reg->command);
+ ? ? ? ? ? ?info->pio_byte_index= 0;
+ ? ? ? ? ? ? break;Looks like you don't use column at all for READID -- no ONFI support, I guess.
Yes.
Quoted 29 lines
Quoted 20 lines
+ ? ? case
NAND_CMD_READ0:
+ ? ? ? ? ? ?writel(NAND_CMD_READ0, &info->reg->cmd_reg1);
+ ? ? ? ? ? ?writel(NAND_CMD_READSTART, &info->reg->cmd_reg2);
+ ? ? ? ? ? ? writel((page_addr << 16) | (column &0xFFFF),
+ ? ? ? ? ? ? ? ? ? ?&info->reg->addr_reg1);
+ ? ? ? ? ? ?writel(page_addr >> 16, &info->reg->addr_reg2);
+ ? ? ? ? ? ? return;
+ ? ? caseNAND_CMD_SEQIN:
+ ? ? ? ? ? ?writel(NAND_CMD_SEQIN, &info->reg->cmd_reg1);
+ ? ? ? ? ? ?writel(NAND_CMD_PAGEPROG, &info->reg->cmd_reg2);
+ ? ? ? ? ? ? writel((page_addr << 16) | (column &0xFFFF),
+ ? ? ? ? ? ? ? ? ? ?&info->reg->addr_reg1);
+ ? ? ? ? ? ? writel(page_addr >> 16,
+ ? ? ? ? ? ? ? ? ? ?&info->reg->addr_reg2);
+ ? ? ? ? ? ? return;
+ ? ? caseNAND_CMD_PAGEPROG:
+ ? ? ? ? ? ? return;
+ ? ? caseNAND_CMD_ERASE1:
+ ? ? ? ? ? ?writel(NAND_CMD_ERASE1, &info->reg->cmd_reg1);Quoted 8 lines
+ ? ? ? ? ? ?
writel(NAND_CMD_ERASE2, &info->reg->cmd_reg2);
+ ? ? ? ? ? ?writel(page_addr, &info->reg->addr_reg1);
+ ? ? ? ? ? ? writel(CMD_GO |CMD_CLE|CMD_ALE|
+ ? ? ? ? ? ? ? ? ? ?CMD_SEC_CMD|CMD_CE0|CMD_ALE_BYTES3,
+ ? ? ? ? ? ? ? ? ? ?&info->reg->command);
+ ? ? ? ? ? ? break;
+ ? ? caseNAND_CMD_RNDOUT:
+ ? ? ? ? ? ? return;
Quoted 2 lines
Don't silently ignore RNDOUT -- if you don't support it and it happens, complain loudly.
OK, I added a printf(), that should be loud enough. Would prefer a debug() though.
Quoted 20 lines
Quoted 11 lines
+ ? ? case
NAND_CMD_ERASE2:
+ ? ? ? ? ? ? return;
+ ? ? caseNAND_CMD_STATUS:
+ ? ? ? ? ? ?writel(NAND_CMD_STATUS, &info->reg->cmd_reg1);
+ ? ? ? ? ? ? writel(CMD_GO |CMD_CLE|CMD_PIO|CMD_RX
+ ? ? ? ? ? ? ? ? ? ? | (CMD_TRANS_SIZE_BYTES1<<
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ?CMD_TRANS_SIZE_SHIFT)
+ ? ? ? ? ? ? ? ? ? ? |CMD_CE0,
+ ? ? ? ? ? ? ? ? ? ?&info->reg->command);
+ ? ? ? ? ? ?info->pio_byte_index= 0;Quoted 8 lines
+ ? ? ? ? ? ? break;
+ ? ? caseNAND_CMD_RESET:
+ ? ? ? ? ? ?writel(NAND_CMD_RESET, &info->reg->cmd_reg1);
+ ? ? ? ? ? ? writel(CMD_GO |CMD_CLE|CMD_CE0,
+ ? ? ? ? ? ? ? ? ? ?&info->reg->command);
+ ? ? ? ? ? ? break;
+ ? ? default:
+ ? ? ? ? ? ? return;
Quoted 1 line
Likewise, complain if you get an unrecognized command.
Done - I wonder why we can't just return an error?
Quoted 27 lines
Quoted 14 lines
(quoted diff) +13
-0+/** + * Set up NAND bus width and page size + * + * @param info ? ? ? ? ? ? ? nand_info structure + * @param *reg_val ? address of reg_val + * @return none - value is set in reg_val + */ +static void set_bus_width_page_size(struct fdt_nand *config, + ? ? u32 *reg_val) +{ + ? ? if (config->width == 8) + ? ? ? ? ? ? *reg_val = CFG_BUS_WIDTH_8BIT; + ? ? elseReview
Quoted 10 lines
(quoted diff) +10
-0+ ? ? ? ? ? ? *reg_val = CFG_BUS_WIDTH_16BIT; + + ? ? if (config->page_data_bytes == 256) + ? ? ? ? ? ? *reg_val |= CFG_PAGE_SIZE_256; + ? ? else if (config->page_data_bytes == 512) + ? ? ? ? ? ? *reg_val |= CFG_PAGE_SIZE_512; + ? ? else if (config->page_data_bytes == 1024) + ? ? ? ? ? ? *reg_val |= CFG_PAGE_SIZE_1024; + ? ? else if (config->page_data_bytes == 2048) + ? ? ? ? ? ? *reg_val |= CFG_PAGE_SIZE_2048;Really, page sizes of 256 and 1024 bytes?
Quoted 3 lines
From elsewhere in the driver you only support 2048 byte pages, so why not just check for that and error (not silently continue) if it's anything else?
I don't think it is that bad - I believe the driver should all the options, although I have not tested it or gone into it carefully. Have added error checking.
Quoted 22 lines
Quoted 22 lines
(quoted diff) +21
-0+} + +/** + * Page read/write function + * + * @param mtd ? ? ? ? ? ? ? ?mtd info structure + * @param chip ? ? ? ? ? ? ? nand chip info structure + * @param buf ? ? ? ? ? ? ? ?data buffer + * @param page ? ? ? ? ? ? ? page number + * @param with_ecc ? 1 to enable ECC, 0 to disable ECC + * @param is_writing 0 for read, 1 for write + * @return ? 0 when successfully completed + * ? ? ? ? ? -EIO when command timeout + */ +static int nand_rw_page(struct mtd_info *mtd, struct nand_chip *chip, + ? ? uint8_t *buf, int page, int with_ecc, int is_writing) +{ + ? ? u32 reg_val; + ? ? int tag_size; + ? ? struct nand_oobfree *free = chip->ecc.layout->oobfree; + ? ? /* 128 is larger than the value that our HW can support. */
Quoted 8 lines
Quoted 6 lines
+ ? ? u32 tag_buf[128];
+ ? ? char*tag_ptr;
+ ? ? structnand_info*info;
+ ? ? structfdt_nand*config;
+
+ ? ? if (((int) buf) &0x03) {s/int/uintptr_t/ (or unsigned long)
done
Quoted 4 lines
Quoted 2 lines
+ ? ? ? ? ? ?
printf("buf 0x%X has to be 4-byte aligned\n", (u32) buf);%p
done
Quoted 6 lines
Quoted 2 lines
+ ? ?
set_bus_width_page_size(&info->config, ®_val);You need to set up the bus width and page size on every page transfer? Why not figure out the value to write in the register at init time (thus making it a good place to reject unsupported configurations)?
Done, added a check to the init.
Quoted 43 lines
Quoted 43 lines
+ ? ? /* Set ECC selection, configure ECC settings */
+ ? ? if (with_ecc) {
+ ? ? ? ? ? ?tag_size=config->tag_bytes+config->tag_ecc_bytes;+ ? ? ? ? ? ? reg_val |= (CFG_SKIP_SPARE_SEL_4 + ? ? ? ? ? ? ? ? ? ? | CFG_SKIP_SPARE_ENABLE + ? ? ? ? ? ? ? ? ? ? | CFG_HW_ECC_CORRECTION_ENABLE + ? ? ? ? ? ? ? ? ? ? | CFG_ECC_EN_TAG_DISABLE + ? ? ? ? ? ? ? ? ? ? | CFG_HW_ECC_SEL_RS + ? ? ? ? ? ? ? ? ? ? | CFG_HW_ECC_ENABLE + ? ? ? ? ? ? ? ? ? ? | CFG_TVAL4 + ? ? ? ? ? ? ? ? ? ? | (tag_size - 1));(quoted diff) +31
-0+ + ? ? ? ? ? ? if (!is_writing) { + ? ? ? ? ? ? ? ? ? ? tag_size += config->skipped_spare_bytes; + ? ? ? ? ? ? ? ? ? ? invalidate_dcache_range((unsigned long) tag_ptr, + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ((unsigned long) tag_ptr) + tag_size); + ? ? ? ? ? ? } else + ? ? ? ? ? ? ? ? ? ? flush_dcache_range((unsigned long) tag_ptr, + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ((unsigned long) tag_ptr) + tag_size); + ? ? } else { + ? ? ? ? ? ? tag_size = mtd->oobsize; + ? ? ? ? ? ? reg_val |= (CFG_SKIP_SPARE_DISABLE + ? ? ? ? ? ? ? ? ? ? | CFG_HW_ECC_CORRECTION_DISABLE + ? ? ? ? ? ? ? ? ? ? | CFG_ECC_EN_TAG_DISABLE + ? ? ? ? ? ? ? ? ? ? | CFG_HW_ECC_DISABLE + ? ? ? ? ? ? ? ? ? ? | (tag_size - 1)); + ? ? ? ? ? ? if (!is_writing) { + ? ? ? ? ? ? ? ? ? ? invalidate_dcache_range((unsigned long) chip->oob_poi, + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ((unsigned long) chip->oob_poi) + tag_size); + ? ? ? ? ? ? } else { + ? ? ? ? ? ? ? ? ? ? flush_dcache_range((unsigned long) chip->oob_poi, + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ((unsigned long) chip->oob_poi) + tag_size); + ? ? ? ? ? ? } + ? ? } + ? ? writel(reg_val, &info->reg->config); + + ? ? if (!is_writing) { + ? ? ? ? ? ? invalidate_dcache_range((unsigned long) buf, + ? ? ? ? ? ? ? ? ? ? ((unsigned long) buf) + + ? ? ? ? ? ? ? ? ? ? (1 << chip->page_shift)); + ? ? } else { + ? ? ? ? ? ? flush_dcache_range((unsigned long) buf,
Quoted 8 lines
Quoted 3 lines
+ ? ? ? ? ? ? ? ? ? ? ((unsigned long) buf) +
+ ? ? ? ? ? ? ? ? ? ? (1 <<chip->page_shift));
+ ? ? }Please factor out all this cache stuff into a dma prepare function that takes start, length, and
is_writing. ?Is it even really needed to invalidate rather than flush in the read case? ?It doesn't look like these buffers are even going to be cacheline-aligned...
Done
I am not keen on adding cache alignment into every driver - IMO this should happen at the level above as with MMC, USB, etc. A fairly trivial fix to nand_base caches most of the problems. I will include a patch in my next series. Anyway for now, Tegra has cache off because of all these warnings.
Quoted 27 lines
Quoted 27 lines
(quoted diff) +26
-0+int fdt_decode_nand(const void *blob, int node, struct fdt_nand *config) +{ + ? ? int err; + + ? ? config->reg = (struct nand_ctlr *)fdtdec_get_addr(blob, node, "reg"); + ? ? config->enabled = fdtdec_get_is_enabled(blob, node); + ? ? config->width = fdtdec_get_int(blob, node, "width", 8); + ? ? err = fdtdec_decode_gpio(blob, node, "wp-gpios", &config->wp_gpio); + ? ? if (err) + ? ? ? ? ? ? return err; + ? ? err = fdtdec_get_int_array(blob, node, "nvidia,timing", + ? ? ? ? ? ? ? ? ? ? config->timing, FDT_NAND_TIMING_COUNT); + ? ? if (err < 0) + ? ? ? ? ? ? return err; + + ? ? /* Now look up the controller and decode that */ + ? ? node = fdt_next_node(blob, node, NULL); + ? ? if (node < 0) + ? ? ? ? ? ? return node; + + ? ? config->page_data_bytes = fdtdec_get_int(blob, node, + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? "page-data-bytes", -1); + ? ? config->tag_ecc_bytes = fdtdec_get_int(blob, node, + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? "tag-ecc-bytes", -1); + ? ? config->tag_bytes = fdtdec_get_int(blob, node, "tag-bytes", -1); + ? ? config->data_ecc_bytes = fdtdec_get_int(blob, node,
Quoted 8 lines
Quoted 5 lines
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? "data-ecc-bytes", -1);
+ ? ?config->skipped_spare_bytes= fdtdec_get_int(blob, node,
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? "skipped-spare-bytes", -1);
+ ? ?config->page_spare_bytes= fdtdec_get_int(blob, node,
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? "page-spare-bytes", -1);Has this binding been accepted into Linux's documentation or another canonical source?
No
Quoted 3 lines
Usually vendor prefixes are asked for on such properties (similar to "nvidia,timing").
Done
Quoted 11 lines
Quoted 2 lines
+/* Oh dear I suspect no one will like these Bit values? */
Indeed.
Quoted 4 lines
+enum {
+ ? ? Bit0 = 1 << 0,
+ ? ? Bit1 = 1 << 1,
+ ? ? Bit2 = 1 << 2,Please just open code this in the functional definitions.
Done
Quoted 14 lines
Review
Quoted 12 lines
(quoted diff) +11
-0+enum { + ? ? CMD_TRANS_SIZE_BYTES1 = 0, + ? ? CMD_TRANS_SIZE_BYTES2, + ? ? CMD_TRANS_SIZE_BYTES3, + ? ? CMD_TRANS_SIZE_BYTES4, + ? ? CMD_TRANS_SIZE_BYTES5, + ? ? CMD_TRANS_SIZE_BYTES6, + ? ? CMD_TRANS_SIZE_BYTES7, + ? ? CMD_TRANS_SIZE_BYTES8, + ? ? CMD_TRANS_SIZE_BYTES_PAGE_SIZE_SEL +};Why not just use the number of bytes directly, minus one?
Done, except for the last one which makes sense as a define I think.
Quoted 3 lines
-Scott
Regards,
Simon
PATCH 5/6 tegra: nand: Add Tegra NAND driver
Quoted 9 lines · Simon Glass
Hi Scott,
Quoted 4 lines · Scott Wood
Quoted 1 line · Simon Glass
+struct
nand_infonand_ctrl;static (or better, dynamic).
Done, what is dynamic?
Allocate the structure dynamically in your init function, and write the code in such a way as to allow multiple instances. Not mandatory if you really think you'll never have multiple instances, but would be nice and shouldn't complicate things much.
Quoted 11 lines
Quoted 10 lines
drivers/mtd/nand/tegra2_nand.c line 171
Quoted 8 lines
drivers/mtd/nand/tegra2_nand.c new file +8
-0+struct nand_info *info; + + info = (struct nand_info *) chip->priv; + + dword_read =readl (&info->reg->resp); + dword_read = dword_read >> (8 * info->pio_byte_index); + info->pio_byte_index++; +return (uint8_t ) dword_read;No space after casts.
Quoted 8 lines
I think I have fixed that globally.
Quoted 3 lines
What happens when
pio_byte_index> 3? Please don't assume that upper bits will be ignored, even if that happens to be true on this chip.I added an
assert()- there is no way to return an error here. I'm not sure what you mean by upper bits - there is auint8_tcast.
By upper bits I mean in the shift count. Don't assume that dword_read >> 32 is the same as dword_read >> 0. It's undefined in C.
Quoted 20 lines
Quoted 8 lines
How does
info->reg->respwork? You don't seem to be choosing the dword to read based onpio_byte_index, which suggests that the act of reading resp changes what will be read the next time. But, you read it on each byte, which would advance resp four times too fast if it's simply returning a new dword each time.If the hardware is really auto-advancing resp only on every fourth access, that needs a comment.
I was just looking at that. Have added a comment.
Quoted 8 lines
drivers/mtd/nand/tegra2_nand.c line 288
Quoted 6 lines
drivers/mtd/nand/tegra2_nand.c new file +5
-0+/* Hardware specific access to control-lines */ +static void nand_hwcontrol (struct mtd_info *mtd,int cmd, +unsigned int ctrl) +{ +}Don't implement this at all if it doesn't make sense for this hardware.
Quoted 3 lines
It isn't implemented (the function is empty), but if it is not defined then the NAND layer will die when it calls a null function. What should I do here?
It should only be called if you don't replace nand_command[_lp] and nand_select_chip. If it's because of nand_select_chip, I'd rather see a dummy implementation of that.
Quoted 28 lines
Quoted 28 lines
Quoted 27 lines
drivers/mtd/nand/tegra2_nand.c new file +27
-0+case NAND_CMD_READ0 : +writel (NAND_CMD_READ0 , &info->reg->cmd_reg1); +writel (NAND_CMD_READSTART , &info->reg->cmd_reg2); +writel ((page_addr <<16 ) | (column &0xFFFF ), + &info->reg->addr_reg1); +writel (page_addr >>16 , &info->reg->addr_reg2); +return ; +case NAND_CMD_SEQIN : +writel (NAND_CMD_SEQIN , &info->reg->cmd_reg1); +writel (NAND_CMD_PAGEPROG , &info->reg->cmd_reg2); +writel ((page_addr <<16 ) | (column &0xFFFF ), + &info->reg->addr_reg1); +writel (page_addr >>16 , + &info->reg->addr_reg2); +return ; +case NAND_CMD_PAGEPROG : +return ; +case NAND_CMD_ERASE1 : +writel (NAND_CMD_ERASE1 , &info->reg->cmd_reg1); +writel (NAND_CMD_ERASE2 , &info->reg->cmd_reg2); +writel (page_addr, &info->reg->addr_reg1); +writel (CMD_GO |CMD_CLE |CMD_ALE | +CMD_SEC_CMD |CMD_CE0 |CMD_ALE_BYTES3 , + &info->reg->command); +break ; +case NAND_CMD_RNDOUT : +return ;
Quoted 5 lines
Quoted 2 lines
Don't silently ignore RNDOUT -- if you don't support it and it happens, complain loudly.
OK, I added a
printf(), that should be loud enough. Would prefer adebug()though.
I don't think it should be debug() -- this is indicating a problem (you could be losing data), not just potentially helpful information.
Quoted 19 lines
Quoted 19 lines
Quoted 18 lines
drivers/mtd/nand/tegra2_nand.c new file +18
-0+case NAND_CMD_ERASE2 : +return ; +case NAND_CMD_STATUS : +writel (NAND_CMD_STATUS , &info->reg->cmd_reg1); +writel (CMD_GO |CMD_CLE |CMD_PIO |CMD_RX + | (CMD_TRANS_SIZE_BYTES1 << +CMD_TRANS_SIZE_SHIFT ) + |CMD_CE0 , + &info->reg->command); + info->pio_byte_index =0 ; +break ; +case NAND_CMD_RESET : +writel (NAND_CMD_RESET , &info->reg->cmd_reg1); +writel (CMD_GO |CMD_CLE |CMD_CE0 , + &info->reg->command); +break ; +default : +return ;
Quoted 3 lines
Quoted 1 line
Likewise, complain if you get an unrecognized command.
Done - I wonder why we can't just return an error?
Because the interface wasn't designed to allow that, unfortunately. If you want to change that, start in Linux.
Quoted 26 lines
Quoted 26 lines
Quoted 13 lines
drivers/mtd/nand/tegra2_nand.c new file +13
-0+/** +* Set up NAND bus width and page size +* +* @param info nand_info structure +* @param *reg_val address of reg_val +* @return none - value is set in reg_val +*/ +static void set_bus_width_page_size (struct fdt_nand *config, +u32 *reg_val) +{ +if (config->width ==8 ) + *reg_val =CFG_BUS_WIDTH_8BIT ; +else drivers/mtd/nand/tegra2_nand.c line 538
Quoted 10 lines
drivers/mtd/nand/tegra2_nand.c new file +10
-0+ *reg_val =CFG_BUS_WIDTH_16BIT ; + +if (config->page_data_bytes ==256 ) + *reg_val |=CFG_PAGE_SIZE_256 ; +else if (config->page_data_bytes ==512 ) + *reg_val |=CFG_PAGE_SIZE_512 ; +else if (config->page_data_bytes ==1024 ) + *reg_val |=CFG_PAGE_SIZE_1024 ; +else if (config->page_data_bytes ==2048 ) + *reg_val |=CFG_PAGE_SIZE_2048 ;Really, page sizes of 256 and 1024 bytes?
Quoted 7 lines
Quoted 3 lines
From elsewhere in the driver you only support 2048 byte pages, so why not just check for that and error (not silently continue) if it's anything else?
I don't think it is that bad - I believe the driver should all the options, although I have not tested it or gone into it carefully. Have added error checking.
I've never heard of a NAND chip with 1024-byte pages, and the only reference to 256-byte pages I've seen is in the "museum IDs" section of the ID table.
Can this controller support 4096-byte pages (or 8192)?
Quoted 15 lines
Quoted 10 lines
drivers/mtd/nand/tegra2_nand.c line 636
Quoted 9 lines
drivers/mtd/nand/tegra2_nand.c new file +9
-0+if (!is_writing) { +invalidate_dcache_range ((unsigned long ) buf, + ((unsigned long ) buf) + + (1 << chip->page_shift)); + }else { +flush_dcache_range ((unsigned long ) buf, + ((unsigned long ) buf) + + (1 << chip->page_shift)); + }Quoted 4 lines
Please factor out all this cache stuff into a dma prepare function that takes start, length, and
is_writing. Is it even really needed to invalidate rather than flush in the read case? It doesn't look like these buffers are even going to be cacheline-aligned...
Quoted 7 lines
Done
I am not keen on adding cache alignment into every driver - IMO this should happen at the level above as with MMC, USB, etc. A fairly trivial fix to
nand_basecaches most of the problems. I will include a patch in my next series. Anyway for now, Tegra has cache off because of all these warnings.
Why would nand_base be in a position to know that you have special alignment needs? Most NAND controllers don't do DMA, and many systems don't require cacheline alignment for DMA. Linux hasn't needed this, why does U-Boot?
Quoted 35 lines
Quoted 26 lines
Quoted 26 lines
drivers/mtd/nand/tegra2_nand.c new file +26
-0+int fdt_decode_nand (const void *blob,int node,struct fdt_nand *config) +{ +int err; + + config->reg = (struct nand_ctlr *)fdtdec_get_addr (blob, node,"reg" ); + config->enabled =fdtdec_get_is_enabled (blob, node); + config->width =fdtdec_get_int (blob, node,"width" ,8 ); + err =fdtdec_decode_gpio (blob, node,"wp-gpios" , &config->wp_gpio); +if (err) +return err; + err =fdtdec_get_int_array (blob, node,"nvidia,timing" , + config->timing,FDT_NAND_TIMING_COUNT ); +if (err <0 ) +return err; + +/* Now look up the controller and decode that */ + node =fdt_next_node (blob, node,NULL ); +if (node <0 ) +return node; + + config->page_data_bytes =fdtdec_get_int (blob, node, +"page-data-bytes" ,-1 ); + config->tag_ecc_bytes =fdtdec_get_int (blob, node, +"tag-ecc-bytes" ,-1 ); + config->tag_bytes =fdtdec_get_int (blob, node,"tag-bytes" ,-1 ); + config->data_ecc_bytes = fdtdec_get_int(blob, node,Quoted 8 lines
drivers/mtd/nand/tegra2_nand.c line 1004
Quoted 5 lines
drivers/mtd/nand/tegra2_nand.c new file +5
-0+ "data-ecc-bytes", -1); + config->skipped_spare_bytes =fdtdec_get_int (blob, node, +"skipped-spare-bytes" ,-1 ); + config->page_spare_bytes =fdtdec_get_int (blob, node, +"page-spare-bytes" ,-1 );Has this binding been accepted into Linux's documentation or another canonical source?
Quoted 1 line
No
It would be good to get that settled first. I assume you'll want to use this binding with Linux eventually.
This code also needs better namespacing -- this isn't applicable for all NAND controllers/bindings.
-Scott
PATCH 5/6 tegra: nand: Add Tegra NAND driver
Hi Scott,
Quoted 7 lines · Scott Wood
Quoted 6 lines · Simon Glass
Hi Scott,
Quoted 3 lines · Scott Wood
Quoted 1 line · Simon Glass
+struct
nand_infonand_ctrl;
Quoted 8 lines
Quoted 3 lines
Quoted 1 line
static (or better, dynamic).
Done, what is dynamic?
Allocate the structure dynamically in your init function, and write the code in such a way as to allow multiple instances. ?Not mandatory if you really think you'll never have multiple instances, but would be nice and shouldn't complicate things much.
There can be only one in Tegra, at least with current devices.
Quoted 15 lines
Quoted 15 lines
Quoted 11 lines
Review
Quoted 9 lines
+ ? ? struct
nand_info*info;(quoted diff) +7
-0+ + ? ? info = (struct nand_info *) chip->priv; + + ? ? dword_read = readl(&info->reg->resp); + ? ? dword_read = dword_read >> (8 * info->pio_byte_index); + ? ? info->pio_byte_index++; + ? ? return (uint8_t) dword_read;No space after casts.
I think I have fixed that globally.
Quoted 1 line
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
What happens when
pio_byte_index> 3? ?Please don't assume that upper bits will be ignored, even if that happens to be true on this chip.I added an
assert()- there is no way to return an error here. I'm not sure what you mean by upper bits - there is auint8_tcast.By upper bits I mean in the shift count. ?Don't assume that
dword_read>> 32 is the same asdword_read>> 0. ?It's undefined in C.
OK I see, I have handled that.
Quoted 21 lines
Quoted 21 lines
Quoted 9 lines
How does
info->reg->respwork? ?You don't seem to be choosing the dword to read based onpio_byte_index, which suggests that the act of reading resp changes what will be read the next time. ?But, you read it on each byte, which would advance resp four times too fast if it's simply returning a new dword each time.If the hardware is really auto-advancing resp only on every fourth access, that needs a comment.
I was just looking at that. Have added a comment.
Quoted 8 lines
drivers/mtd/nand/tegra2_nand.c line 288
Quoted 6 lines
drivers/mtd/nand/tegra2_nand.c new file +5
-0+/* Hardware specific access to control-lines */ +static void nand_hwcontrol (struct mtd_info *mtd,int cmd, + ? ? unsigned int ctrl) +{ +}Don't implement this at all if it doesn't make sense for this hardware.
Quoted 7 lines
Quoted 3 lines
It isn't implemented (the function is empty), but if it is not defined then the NAND layer will die when it calls a null function. What should I do here?
It should only be called if you don't replace nand_command[_lp] and
nand_select_chip. ?If it's because ofnand_select_chip, I'd rather see a dummy implementation of that.
OK I see, will change it.
Quoted 29 lines
Quoted 29 lines
Quoted 29 lines
Quoted 28 lines
+ ? ? case
NAND_CMD_READ0:
+ ? ? ? ? ? ?writel(NAND_CMD_READ0, &info->reg->cmd_reg1);
+ ? ? ? ? ? ?writel(NAND_CMD_READSTART, &info->reg->cmd_reg2);
+ ? ? ? ? ? ? writel((page_addr << 16) | (column &0xFFFF),
+ ? ? ? ? ? ? ? ? ? ?&info->reg->addr_reg1);
+ ? ? ? ? ? ?writel(page_addr >> 16, &info->reg->addr_reg2);
+ ? ? ? ? ? ? return;
+ ? ? caseNAND_CMD_SEQIN:
+ ? ? ? ? ? ?writel(NAND_CMD_SEQIN, &info->reg->cmd_reg1);
+ ? ? ? ? ? ?writel(NAND_CMD_PAGEPROG, &info->reg->cmd_reg2);
+ ? ? ? ? ? ? writel((page_addr << 16) | (column &0xFFFF),
+ ? ? ? ? ? ? ? ? ? ?&info->reg->addr_reg1);
+ ? ? ? ? ? ? writel(page_addr >> 16,
+ ? ? ? ? ? ? ? ? ? ?&info->reg->addr_reg2);
+ ? ? ? ? ? ? return;
+ ? ? caseNAND_CMD_PAGEPROG:
+ ? ? ? ? ? ? return;
+ ? ? caseNAND_CMD_ERASE1:
+ ? ? ? ? ? ?writel(NAND_CMD_ERASE1, &info->reg->cmd_reg1);
+ ? ? ? ? ? ?writel(NAND_CMD_ERASE2, &info->reg->cmd_reg2);
+ ? ? ? ? ? ?writel(page_addr, &info->reg->addr_reg1);
+ ? ? ? ? ? ? writel(CMD_GO |CMD_CLE|CMD_ALE|
+ ? ? ? ? ? ? ? ? ? ?CMD_SEC_CMD|CMD_CE0|CMD_ALE_BYTES3,
+ ? ? ? ? ? ? ? ? ? ?&info->reg->command);
+ ? ? ? ? ? ? break;
+ ? ? caseNAND_CMD_RNDOUT:
+ ? ? ? ? ? ? return;
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
Don't silently ignore RNDOUT -- if you don't support it and it happens, complain loudly.
OK, I added a
printf(), that should be loud enough. Would prefer adebug()though.I don't think it should be
debug()-- this is indicating a problem (you could be losing data), not just potentially helpful information.
Yes, the API should be changed to return a value, then a debug might be useful.
Quoted 20 lines
Quoted 20 lines
Quoted 20 lines
Quoted 19 lines
+ ? ? case
NAND_CMD_ERASE2:
+ ? ? ? ? ? ? return;
+ ? ? caseNAND_CMD_STATUS:
+ ? ? ? ? ? ?writel(NAND_CMD_STATUS, &info->reg->cmd_reg1);
+ ? ? ? ? ? ? writel(CMD_GO |CMD_CLE|CMD_PIO|CMD_RX
+ ? ? ? ? ? ? ? ? ? ? | (CMD_TRANS_SIZE_BYTES1<<
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ?CMD_TRANS_SIZE_SHIFT)
+ ? ? ? ? ? ? ? ? ? ? |CMD_CE0,
+ ? ? ? ? ? ? ? ? ? ?&info->reg->command);
+ ? ? ? ? ? ?info->pio_byte_index= 0;
+ ? ? ? ? ? ? break;
+ ? ? caseNAND_CMD_RESET:
+ ? ? ? ? ? ?writel(NAND_CMD_RESET, &info->reg->cmd_reg1);
+ ? ? ? ? ? ? writel(CMD_GO |CMD_CLE|CMD_CE0,
+ ? ? ? ? ? ? ? ? ? ?&info->reg->command);
+ ? ? ? ? ? ? break;
+ ? ? default:
+ ? ? ? ? ? ? return;
Quoted 6 lines
Quoted 3 lines
Quoted 1 line
Likewise, complain if you get an unrecognized command.
Done - I wonder why we can't just return an error?
Because the interface wasn't designed to allow that, unfortunately. ?If you want to change that, start in Linux.
http://www.youtube.com/watch?v=K8E_zMLCRNg
Quoted 31 lines
Quoted 31 lines
Quoted 30 lines
Quoted 14 lines
(quoted diff) +13
-0+/** + * Set up NAND bus width and page size + * + * @param info ? ? ? ? ? ? ? nand_info structure + * @param *reg_val ? address of reg_val + * @return none - value is set in reg_val + */ +static void set_bus_width_page_size(struct fdt_nand *config, + ? ? u32 *reg_val) +{ + ? ? if (config->width == 8) + ? ? ? ? ? ? *reg_val = CFG_BUS_WIDTH_8BIT; + ? ? elseReview
Quoted 10 lines
(quoted diff) +10
-0+ ? ? ? ? ? ? *reg_val = CFG_BUS_WIDTH_16BIT; + + ? ? if (config->page_data_bytes == 256) + ? ? ? ? ? ? *reg_val |= CFG_PAGE_SIZE_256; + ? ? else if (config->page_data_bytes == 512) + ? ? ? ? ? ? *reg_val |= CFG_PAGE_SIZE_512; + ? ? else if (config->page_data_bytes == 1024) + ? ? ? ? ? ? *reg_val |= CFG_PAGE_SIZE_1024; + ? ? else if (config->page_data_bytes == 2048) + ? ? ? ? ? ? *reg_val |= CFG_PAGE_SIZE_2048;Really, page sizes of 256 and 1024 bytes?
From elsewhere in the driver you only support 2048 byte pages, so why not just check for that and error (not silently continue) if it's anything else?
Quoted 7 lines
Quoted 3 lines
I don't think it is that bad - I believe the driver should all the options, although I have not tested it or gone into it carefully. Have added error checking.
I've never heard of a NAND chip with 1024-byte pages, and the only reference to 256-byte pages I've seen is in the "museum IDs" section of the ID table.
I will remove them then.
Quoted 2 lines
Can this controller support 4096-byte pages (or 8192)?
Have added 4096, but I don't think it supports 8192 (shown as 'reserved' in datasheet).
Quoted 24 lines
Quoted 16 lines
Quoted 11 lines
Quoted 10 lines
+ ? ? if (!is_writing) {
+ ? ? ? ? ? ? invalidate_dcache_range((unsigned long) buf,
+ ? ? ? ? ? ? ? ? ? ? ((unsigned long) buf) +
+ ? ? ? ? ? ? ? ? ? ? (1 <<chip->page_shift));
+ ? ? } else {
+ ? ? ? ? ? ? flush_dcache_range((unsigned long) buf,
+ ? ? ? ? ? ? ? ? ? ? ((unsigned long) buf) +
+ ? ? ? ? ? ? ? ? ? ? (1 <<chip->page_shift));
+ ? ? }Quoted 4 lines
Please factor out all this cache stuff into a dma prepare function that takes start, length, and
is_writing. ?Is it even really needed to invalidate rather than flush in the read case? ?It doesn't look like these buffers are even going to be cacheline-aligned...Quoted 7 lines
Done
I am not keen on adding cache alignment into every driver - IMO this should happen at the level above as with MMC, USB, etc. A fairly trivial fix to
nand_basecaches most of the problems. I will include a patch in my next series. Anyway for now, Tegra has cache off because of all these warnings.
Quoted 4 lines
Why would
nand_basebe in a position to know that you have special alignment needs? ?Most NAND controllers don't do DMA, and many systems don't require cacheline alignment for DMA. ?Linux hasn't needed this, why does U-Boot?
There is now an ARCH_DMA_MINALIGN define in U-Boot, and a ALLOC_CACHE_ALIGN_BUFFER macro just for this purpose. There has been some effort in making things like ext2, mmc and USB work properly with DMA alignment. I don't see any need to make it hard to the driver - if we can avoid bounce buffers we should.
Quoted 36 lines
Quoted 36 lines
Quoted 35 lines
Quoted 22 lines
(quoted diff) +21
-0+int fdt_decode_nand(const void *blob, int node, struct fdt_nand *config) +{ + ? ? int err; + + ? ? config->reg = (struct nand_ctlr *)fdtdec_get_addr(blob, node, "reg"); + ? ? config->enabled = fdtdec_get_is_enabled(blob, node); + ? ? config->width = fdtdec_get_int(blob, node, "width", 8); + ? ? err = fdtdec_decode_gpio(blob, node, "wp-gpios", &config->wp_gpio); + ? ? if (err) + ? ? ? ? ? ? return err; + ? ? err = fdtdec_get_int_array(blob, node, "nvidia,timing", + ? ? ? ? ? ? ? ? ? ? config->timing, FDT_NAND_TIMING_COUNT); + ? ? if (err < 0) + ? ? ? ? ? ? return err; + + ? ? /* Now look up the controller and decode that */ + ? ? node = fdt_next_node(blob, node, NULL); + ? ? if (node < 0) + ? ? ? ? ? ? return node; + + ? ? config->page_data_bytes = fdtdec_get_int(blob, node,Review
Quoted 10 lines
(quoted diff) +10
-0+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? "page-data-bytes", -1); + ? ? config->tag_ecc_bytes = fdtdec_get_int(blob, node, + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? "tag-ecc-bytes", -1); + ? ? config->tag_bytes = fdtdec_get_int(blob, node, "tag-bytes", -1); + ? ? config->data_ecc_bytes = fdtdec_get_int(blob, node, + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? "data-ecc-bytes", -1); + ? ? config->skipped_spare_bytes = fdtdec_get_int(blob, node, + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? "skipped-spare-bytes", -1); + ? ? config->page_spare_bytes = fdtdec_get_int(blob, node, + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? "page-spare-bytes", -1);Has this binding been accepted into Linux's documentation or another canonical source?
Quoted 4 lines
Quoted 1 line
No
It would be good to get that settled first. ?I assume you'll want to use this binding with Linux eventually.
I am not sure - from what I hear Linux does ID lookup instead - but really this binding is only useful without ONFI support I suspect.
Quoted 3 lines
This code also needs better namespacing -- this isn't applicable for all NAND controllers/bindings.
Do you mean the "nvidia," prefix?
I will send another version of the series with comments received so far addressed.
Quoted 3 lines
-Scott
Regards,
Simon
PATCH 5/6 tegra: nand: Add Tegra NAND driver
Quoted 15 lines · Simon Glass
Hi Scott,
Quoted 11 lines · Scott Wood
Quoted 5 lines · Simon Glass
I am not keen on adding cache alignment into every driver - IMO this should happen at the level above as with MMC, USB, etc. A fairly trivial fix to
nand_basecaches most of the problems. I will include a patch in my next series. Anyway for now, Tegra has cache off because of all these warnings.Why would
nand_basebe in a position to know that you have special alignment needs? Most NAND controllers don't do DMA, and many systems don't require cacheline alignment for DMA. Linux hasn't needed this, why does U-Boot?
Quoted 5 lines
There is now an
ARCH_DMA_MINALIGNdefine in U-Boot, and aALLOC_CACHE_ALIGN_BUFFERmacro just for this purpose. There has been some effort in making things like ext2, mmc and USB work properly with DMA alignment. I don't see any need to make it hard to the driver - if we can avoid bounce buffers we should.
I understand the desire to avoid bounce buffers, but I also don't want to introduce unnecessary differences between Linux and U-Boot in nand_base.c. How does your Linux driver handle this?
Quoted 35 lines
Quoted 35 lines
Quoted 35 lines
Quoted 34 lines
Quoted 21 lines
drivers/mtd/nand/tegra2_nand.c new file +21
-0+int fdt_decode_nand (const void *blob,int node,struct fdt_nand *config) +{ +int err; + + config->reg = (struct nand_ctlr *)fdtdec_get_addr (blob, node,"reg" ); + config->enabled =fdtdec_get_is_enabled (blob, node); + config->width =fdtdec_get_int (blob, node,"width" ,8 ); + err =fdtdec_decode_gpio (blob, node,"wp-gpios" , &config->wp_gpio); +if (err) +return err; + err =fdtdec_get_int_array (blob, node,"nvidia,timing" , + config->timing,FDT_NAND_TIMING_COUNT ); +if (err <0 ) +return err; + +/* Now look up the controller and decode that */ + node =fdt_next_node (blob, node,NULL ); +if (node <0 ) +return node; + + config->page_data_bytes = fdtdec_get_int(blob, node,drivers/mtd/nand/tegra2_nand.c line 1004
Quoted 10 lines
drivers/mtd/nand/tegra2_nand.c new file +10
-0+ "page-data-bytes", -1); + config->tag_ecc_bytes =fdtdec_get_int (blob, node, +"tag-ecc-bytes" ,-1 ); + config->tag_bytes =fdtdec_get_int (blob, node,"tag-bytes" ,-1 ); + config->data_ecc_bytes =fdtdec_get_int (blob, node, +"data-ecc-bytes" ,-1 ); + config->skipped_spare_bytes =fdtdec_get_int (blob, node, +"skipped-spare-bytes" ,-1 ); + config->page_spare_bytes =fdtdec_get_int (blob, node, +"page-spare-bytes" ,-1 );Has this binding been accepted into Linux's documentation or another canonical source?
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
No
It would be good to get that settled first. I assume you'll want to use this binding with Linux eventually.
I am not sure - from what I hear Linux does ID lookup instead - but really this binding is only useful without ONFI support I suspect.
I'm not sure what difference you're seeing between U-Boot and Linux. Both U-Boot and Linux uses the ID table in the absence of ONFI.
Quoted 4 lines
Quoted 2 lines
This code also needs better namespacing -- this isn't applicable for all NAND controllers/bindings.
Do you mean the "nvidia," prefix?
No, I mean the fact that this is a global function called "fdt_decode_nand", taking a "struct fdt_nand" argument, that is specific to one controller type.
-Scott
PATCH 5/6 tegra: nand: Add Tegra NAND driver
Hi Scott,
Quoted 22 lines · Scott Wood
Quoted 15 lines · Simon Glass
Hi Scott,
Quoted 11 lines · Scott Wood
Quoted 5 lines · Simon Glass
I am not keen on adding cache alignment into every driver - IMO this should happen at the level above as with MMC, USB, etc. A fairly trivial fix to
nand_basecaches most of the problems. I will include a patch in my next series. Anyway for now, Tegra has cache off because of all these warnings.Why would
nand_basebe in a position to know that you have special alignment needs? ?Most NAND controllers don't do DMA, and many systems don't require cacheline alignment for DMA. ?Linux hasn't needed this, why does U-Boot?Quoted 5 lines
There is now an
ARCH_DMA_MINALIGNdefine in U-Boot, and aALLOC_CACHE_ALIGN_BUFFERmacro just for this purpose. There has been some effort in making things like ext2, mmc and USB work properly with DMA alignment. I don't see any need to make it hard to the driver - if we can avoid bounce buffers we should.
Quoted 3 lines
I understand the desire to avoid bounce buffers, but I also don't want to introduce unnecessary differences between Linux and U-Boot in
nand_base.c. ?How does your Linux driver handle this?
I have included a patch with the changes in the next version, it's pretty minimal.
I don't see a linux driver in mainline Linux. We did have one in our tree but it seems to be gone also. That one had lots of TODOs, and used bounce buffers from what I can tell.
Quoted 38 lines
Quoted 38 lines
Quoted 38 lines
Quoted 37 lines
Quoted 27 lines
Quoted 27 lines
(quoted diff) +26
-0+int fdt_decode_nand(const void *blob, int node, struct fdt_nand *config) +{ + ? ? int err; + + ? ? config->reg = (struct nand_ctlr *)fdtdec_get_addr(blob, node, "reg"); + ? ? config->enabled = fdtdec_get_is_enabled(blob, node); + ? ? config->width = fdtdec_get_int(blob, node, "width", 8); + ? ? err = fdtdec_decode_gpio(blob, node, "wp-gpios", &config->wp_gpio); + ? ? if (err) + ? ? ? ? ? ? return err; + ? ? err = fdtdec_get_int_array(blob, node, "nvidia,timing", + ? ? ? ? ? ? ? ? ? ? config->timing, FDT_NAND_TIMING_COUNT); + ? ? if (err < 0) + ? ? ? ? ? ? return err; + + ? ? /* Now look up the controller and decode that */ + ? ? node = fdt_next_node(blob, node, NULL); + ? ? if (node < 0) + ? ? ? ? ? ? return node; + + ? ? config->page_data_bytes = fdtdec_get_int(blob, node, + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? "page-data-bytes", -1); + ? ? config->tag_ecc_bytes = fdtdec_get_int(blob, node, + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? "tag-ecc-bytes", -1); + ? ? config->tag_bytes = fdtdec_get_int(blob, node, "tag-bytes", -1); + ? ? config->data_ecc_bytes = fdtdec_get_int(blob, node,Quoted 8 lines
Quoted 5 lines
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? "data-ecc-bytes", -1);
+ ? ?config->skipped_spare_bytes= fdtdec_get_int(blob, node,
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? "skipped-spare-bytes", -1);
+ ? ?config->page_spare_bytes= fdtdec_get_int(blob, node,
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? "page-spare-bytes", -1);Has this binding been accepted into Linux's documentation or another canonical source?
No
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
It would be good to get that settled first. ?I assume you'll want to use this binding with Linux eventually.
I am not sure - from what I hear Linux does ID lookup instead - but really this binding is only useful without ONFI support I suspect.
I'm not sure what difference you're seeing between U-Boot and Linux. Both U-Boot and Linux uses the ID table in the absence of ONFI.
I don't think this driver supports ONFI. I haven't tried it though.
Quoted 9 lines
Quoted 5 lines
Quoted 3 lines
This code also needs better namespacing -- this isn't applicable for all NAND controllers/bindings.
Do you mean the "nvidia," prefix?
No, I mean the fact that this is a global function called "
fdt_decode_nand", taking a "structfdt_nand" argument, that is specific to one controller type.
OK, so rename struct fdt_nand to struct fdt_tegra_nand or similar? I will do this in the next version.
Quoted 3 lines
-Scott
Regards,
Simon
PATCH 5/6 tegra: nand: Add Tegra NAND driver
Quoted 12 lines · Simon Glass
Hi Scott,
Quoted 9 lines · Scott Wood
Quoted 8 lines · Simon Glass
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
Has this binding been accepted into Linux's documentation or another canonical source?
No
It would be good to get that settled first. I assume you'll want to use this binding with Linux eventually.
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
I am not sure - from what I hear Linux does ID lookup instead - but really this binding is only useful without ONFI support I suspect.
I'm not sure what difference you're seeing between U-Boot and Linux. Both U-Boot and Linux uses the ID table in the absence of ONFI.
I don't think this driver supports ONFI. I haven't tried it though.
But even in the absence of ONFI, what is the difference? Both Linux and U-Boot use the ID table. If you need this stuff in U-boot you'll need it in Linux.
-Scott
PATCH 5/6 tegra: nand: Add Tegra NAND driver
Hi Scott,
Quoted 16 lines · Scott Wood
Quoted 15 lines · Simon Glass
Hi Scott,
Quoted 12 lines · Scott Wood
Quoted 10 lines · Simon Glass
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
Has this binding been accepted into Linux's documentation or another canonical source?
No
It would be good to get that settled first. ?I assume you'll want to use this binding with Linux eventually.
I am not sure - from what I hear Linux does ID lookup instead - but really this binding is only useful without ONFI support I suspect.
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines
I'm not sure what difference you're seeing between U-Boot and Linux. Both U-Boot and Linux uses the ID table in the absence of ONFI.
I don't think this driver supports ONFI. I haven't tried it though.
But even in the absence of ONFI, what is the difference? ?Both Linux and U-Boot use the ID table. ?If you need this stuff in U-boot you'll need it in Linux.
Quite possibly, but without a Linux driver it is hard to compare.
Quoted 3 lines
-Scott
Regards,
Simon
PATCH 6/6 tegra: Enable NAND on Seaboard
In reply to Simon GlassThis enables NAND support for the Seaboard.
--- include/configs/seaboard.h | 9 +++++++++ 1 files changed, 9 insertions(+), 0 deletions(-)
include/configs/seaboard.h +9 -0
@@ -105,4 +105,13 @@#define CONFIG_USB_STORAGE #define CONFIG_CMD_USB +/* NAND support */ +#define CONFIG_CMD_NAND +#define CONFIG_TEGRA2_NAND + +/* Max number of NAND devices */ +#define CONFIG_SYS_MAX_NAND_DEVICE 1 + +/* Somewhat oddly, the NAND base address must be a config option */ +#define CONFIG_SYS_NAND_BASE TEGRA2_NAND_BASE#endif /* __CONFIG_H */
Signature · 1 line
1.7.7.3